跨域Ajax请求不要在Opera和IE9工作? [英] Cross-origin Ajax requests don't work in Opera and IE9?

查看:183
本文介绍了跨域Ajax请求不要在Opera和IE9工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个页面 - http://ecmazing.com/cors.html - 做一个跨域的Ajax要求该资源: http://hacheck.tel.fer.hr/xml.pl

I am using this page - http://ecmazing.com/cors.html - to make a cross-origin Ajax request to this resource: http://hacheck.tel.fer.hr/xml.pl

它可以在Chrome浏览器,Safari和Firefox,但不会在IE9和Opera。

It works in Chrome, Safari and Firefox, but doesn't in IE9 and Opera.

在code:

var pdata = {'textarea': 'test'};

$.post('http://hacheck.tel.fer.hr/xml.pl', pdata, function(data, status, xhr) {
    output.value = xhr.responseText;
});

(预期的结果是一个XML code字符串。)

(The expected result is an XML code string.)

查看自己: http://ecmazing.com/cors.html

在IE9和Opera,XHR对象的错误处理程序执行,这个错误对象传递的:

In IE9 and Opera, the error handler of the XHR object executes and this error object is passed in:

{
    readyState: 4,
    status: 0,
    statusText: 'error'
}

正如你所看到的,这个错误对象不透露太多的信息。

As you can see, this error object doesn't reveal much information.

我怎样才能使它在IE9和Opera的工作?

How can I make it work in IE9 and Opera?

推荐答案

请参阅在whencaniuse 获取 CORS的条目。

See the entry for cors at whencaniuse.

对于Internet Explorer CORS是在IE8和IE9使用XDomainRequest对象支持多少有点,所以你需要使用备用对象来使用它。

For Internet Explorer CORS is "Supported somewhat in IE8 and IE9 using the XDomainRequest object", so you need to use an alternate object to use it.

戏根本不支持它。

如果您需要跨域Ajax的歌剧,然后使用JSON-P。

If you need cross-domain Ajax in Opera, then use JSON-P.

这篇关于跨域Ajax请求不要在Opera和IE9工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆