简体   繁体   English

IE6 Ajax 与 JQuery

[英]IE6 Ajax with JQuery

I'm trying to fecth data from a REST webservice into a HTML page.我正在尝试将 REST 网络服务中的数据感染到 HTML 页面中。 The problem is Internet Explorer 6 (which is my target station on XP SP3) that I'm struggling to make work.问题是我正在努力工作的 Internet Explorer 6(这是我在 XP SP3 上的目标站)。 Here's the code used:这是使用的代码:

$.ajax({
       type: "GET",
       contentType:"application/json; charset=utf-8",
       dataType : 'json',
       url: "https://jsonplaceholder.typicode.com/posts/1",
       success: function(data) {
            alert(data);
       },
       complete: function(xhr) {
          alert(xhr.status+" "+xhr.responseText);
       }
});

Tested on Firefox 52 ESR: both success and complete functions works.在 Firefox 52 ESR 上测试:成功和完整的功能都有效。

On Chrome 49: success works, complete is called but xhr.status is 0 and xhr.responseText is empty.在 Chrome 49 上:成功工作,完成被调用,但 xhr.status 为 0 并且 xhr.responseText 为空。

On IE6 success is not called at all and complete is called but xhr.status is 0 and xhr.responseText is undefined.在 IE6 上,根本不调用 success 并调用 complete,但 xhr.status 为 0 且 xhr.responseText 未定义。

Tried what was already answered here on SOF like removing extra commas, adding dataType... but still no success with IE6.尝试了在 SOF 上已经回答的问题,例如删除额外的逗号、添加 dataType ......但在 IE6 上仍然没有成功。

How can we do it once for all?我们怎样才能做到一劳永逸?

Thanks谢谢

IE6 is ancient , it does not support CORS (not even with XDomainRequest ). IE6 很古老,它不支持 CORS (甚至不支持XDomainRequest )。

There is no way to perform cross-origin RESTful HTTP requests with JavaScript in IE6.在 IE6 中无法使用 JavaScript 执行跨域 RESTful HTTP 请求。

If you want to perform a cross-origin request, then you will need to use some other (non-RESTful) approach such as JSONP.如果要执行跨域请求,则需要使用其他(非 RESTful)方法,例如 JSONP。

As Quentin said, sending CORS request is not supported in IE 6/7, you could check this blog .正如 Quentin 所说,IE 6/7 不支持发送 CORS 请求,您可以查看此博客

You could refer to the following code to use JSONP .您可以参考以下代码来使用 JSONP

// Using JSONP
$.ajax({
    url: "<request url>",
    jsonp: "callback",

    // Tell jQuery we're expecting JSONP
    dataType: "jsonp",
    data: {
        q: "select title,abstract,url from search.news where query=\"cat\"",
        format: "json"
    },

    // Work with the response
    success: function( response ) {
        console.log( response ); // server response
    }
});

Besides, please check this article :此外,请查看这篇文章

Internet Explorer 9 and earlier ignores Access-Control-Allow headers and by default prohibits cross-origin requests for Internet Zone. Internet Explorer 9 和更早版本忽略 Access-Control-Allow 标头,默认情况下禁止 Internet 区域的跨域请求。 To enable cross-origin access go to Tools->Internet Options->Security tab, click on “Custom Level” button.要启用跨域访问 go 到工具-> Internet 选项-> 安全选项卡,单击“自定义级别”按钮。 Find the Miscellaneous -> Access data sources across domains setting and select “Enable” option.找到杂项 -> 跨域访问数据源设置和 select “启用”选项。

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

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