Can I use the addon code in my jQuery script (Firefox addon sdk) file? if so, how?

I recently started looking into developing the addon-sdk plugin and am now stuck with an issue. In this plugin, I have now used togglebutton and panel. In the panel I have loaded an html file which is "myform.html" . When I fill out the form uploaded to the panel and click the submit button, with this, the ajax request sends post data to the server and returns a response. The ajax code is in a jquery file named "script.js" . Now with the response, I want to access the current components of the tab (e.g. form, text input type, etc.). when i use chrome objects like self, panel, etc. in the ajax success function, this is giving me errors. I searched a lot to get rid of this error, but nothing was found for me. So tell me if I go in the wrong direction,or am I missing something.

I am doing something like this (script.js) :

$(document).ready(function(e) {
     $('#form').on('submit',function(login){
           $.ajax({
                .....
                .....
                success:function(result){
                     self.port.emit(...);
                }
           });
     });
});

      

+3


source to share


1 answer


You can specify one or more content scripts to be loaded into the panel using the contentScript or contentScriptFile parameters in the Panel () constructor.

You need to make sure jQuery is included in your 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 yours, script.js

you don't need to listen to the event ready

like contentScriptWhen ready

.

 // script.js
 $('#form').on('submit',function(login){
       $.ajax({
            ...
            ...
            success:function(result){
                 self.port.emit('ajaxComplete');
            }
       });
 });

      

We wish you good luck with your project

+1


source







All Articles