html - Can i use addon code in jquery content script file (Firefox addon sdk)? if yes how? -
i started learning addon-sdk plugin development , stucked in problem. in plugin have used togglebutton , panel now. in panel have loaded html file "myform.html". when fill form i.e loaded in panel , click submit button, this, ajax request sends post data server , response returns. ajax code in jquery file named "script.js". now, after receiving response want access current tab page components (eg. form, input type text etc.). when use chrome objects self, panel etc in ajax success function, gives me errors. searched alot rid of error nothing found useful me. tell me if going in wrong direction or missing in it.
i doing (script.js):
$(document).ready(function(e) { $('#form').on('submit',function(login){ $.ajax({ ..... ..... success:function(result){ self.port.emit(...); } }); }); });
you can specify 1 or more content scripts load panel using contentscript or contentscriptfile options panel() constructor.
you should ensure jquery included content scripts.
var self = require("sdk/self"); var panel = require("sdk/panel").panel({ contenturl: "https://en.wikipedia.org/w/index.php?title=jetpack&useformat=mobile", contentscriptfile: [ self.data.url("jquery.js"), self.data.url("script.js"), ] contentscriptwhen: 'ready', }); panel.port.on('ajaxcomplete', function (){ console.log('completed!'); }); panel.show();
in script.js
not need listen ready
event contentscriptwhen ready
.
// script.js $('#form').on('submit',function(login){ $.ajax({ ... ... success:function(result){ self.port.emit('ajaxcomplete'); } }); });
best of luck project
Comments
Post a Comment