简体   繁体   English

如果AJAX请求失败,Firefox附加组件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. 在面板中加载的HTML中,我包含了最新的jquery和一个登录javascript文件。

Actually you can make cross domain request in content script of Firefox extension. 实际上你可以在Firefox扩展的内容脚本中进行跨域请求。 check this link: 检查此链接:

https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/Cross_Domain_Content_Scripts 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: 你需要澄清package.json中的域权限,如下所示:

"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 ). 内容脚本目前无法发出跨域请求(我认为可以使用chrome扩展)。 What you can do instead is make the request in main.js using the request module: 可以做的是使用请求模块在main.js中发出请求:

https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/request.html 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. 从SDK版本1.12开始(将在6周内发布),您能够在内容脚本中进行跨域请求,从而使这种功能更容易实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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