简体   繁体   中英

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.

Actually you can make cross domain request in content script of Firefox extension. check this link:

https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/Cross_Domain_Content_Scripts

you need to clarify the domain permission in package.json like this:

"permissions": {
  "cross-domain-content": ["http://datapoint.metoffice.gov.uk"]
}

[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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM