【问题标题】:Jsonp callback in internet explorer not workingInternet Explorer 中的 Jsonp 回调不起作用
【发布时间】:2016-07-02 06:18:57
【问题描述】:

我正在使用 JSONP 通过 AJAX 从 API 收集数据。我已经在 Firefox 和 chrome 中测试了我的代码,它在这些浏览器中运行良好。

我使用的链接格式如下:
www.placeholder.com/foo/?jsonp=dataCallback

但是,当我尝试在 Internet Explorer 11 中执行完全相同的操作时,我收到一条错误消息:
对象不支持属性或方法“dataCallback”

我注意到在 Firefox 和 chrome 中,当我执行请求时,窗口将包含一个名为“dataCallback”的对象。然而,在 Internet Explorer 11 中,当我执行请求时,窗口中不存在“dataCallback”之类的东西。

        $.support.cors = true;

        $.ajax({
            url: url,
            dataType: "jsonp",
            contentType: "application/javascript",
            crossDomain: true,
            async: true,
            cache: true,
            // Work with the response
            complete: function (response) {
                var data = window["dataCallback"]();
                callback(self.parseData(data, scope, end), transport);
            }
        });

这是一个已知问题吗?我该如何解决?

【问题讨论】:

    标签: jquery ajax internet-explorer jsonp


    【解决方案1】:

    我发现了问题所在。上面的代码非常适合 Internet Explorer。

    出了什么问题,我构建了一个 URL,其中封装了 username:password。显然,Internet Explorer 不支持在 URL 中包含用户名和密码,这就是它失败的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-09
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 2012-01-27
      • 2014-04-03
      • 2014-08-14
      • 2015-03-16
      相关资源
      最近更新 更多