在JSONP调用只能从火狐扩展错误火狐、错误、JSONP

2023-09-10 14:20:33 作者:青酒与书.

有什么奇怪的关于我的错误是,它仅发生在Firefox扩展我已经在这篇文章底部链接。我不能在其他任何设置重现此错误。

what's weird about my error is that it ONLY occurs in the firefox extension I have linked to at the bottom of this post. I cannot reproduce this error in any other setting.

我有这样的Ajax请求

I have this ajax request

$.ajax({
  type: "GET",
  dataType: "jsonp",
  url: url,
  jsonpCallback: "JSONCallback",
  data: {title:$("#txtTitle").val(), url:taburl},
  success: function(data, textStatus) {
    if(data.code > 0)
        {
        $("#icon").removeClass().addClass('accept');
        }
    else
        {
        $("#icon").removeClass().addClass('error');
        if(data.code == '-1')
            alert('kunne ikke finde din ønskeseddel på e-ønsker.dk - besøg e-ønsker.dk, og prøv derefter igen');
        }
  },
  error: function(xhr, textStatus, errorThrown) {
     alert("XMLHttpRequest="+xhr.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
    $("#icon").removeClass().addClass('error');
  }
});

服务器返回

JSONCallback({"code":405});

标题是应用程序/ JSON

为什么我收到一个parseError说JSONCallback不叫?我认为jQuery的应该处理一下吗?

so why am I getting a parseError saying JSONCallback was not called? I thought jQuery was supposed to handle that for me?

在code是 http://builder.addons.mozilla.org /插件/ 1022928 /最新和有问题的文件是数据/ panel.js

the code is from http://builder.addons.mozilla.org/addon/1022928/latest and the file in question is data/panel.js

推荐答案

现在的问题是与窗口。解决这个问题的最简单的方法将是编辑的jQuery code(我知道,我讨厌这样做太)使用 unsafeWindow ,而不是窗口

The problem is with window. The easiest way to fix this will be to edit the jQuery code (I know, I hate doing this too) to use unsafeWindow rather than window.