Search code examples
jqueryfirefox-addon-sdk

Firefox add-on sdk if failing AJAX requests


Please note the following code:

    $.ajax({
     type: "POST",
     url: loginURL,
     data: jsonArray,
     async: true,
     success: function(data, status){
         alert(status);
     },
     error: function(data, status){
         alert(status + " 1");
     }
});

The error case is thrown every time, but I have fiddler open and I'm receiving data from the server just fine. I'm attaching a panel to a widget. In the HTML that gets loaded in the panel, I'm including the latest jquery and a login javascript file.


Solution

  • [EDIT: I updated the link]

    Is this in a content script? Content scripts cannot make cross-domain requests currently ( chrome extensions I think can ). What you can do instead is make the request in main.js using the request module:

    https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/request.html

    As of SDK version 1.12 ( to be released in 6 weeks ) you will be able to make cross-domain requests in content scripts, making this sort of functionality a bit simpler to implement.