Cross-origin Ajax requests don#39;t work in Opera and IE9?(跨域 Ajax 请求在 Opera 和 IE9 中不起作用?)
问题描述
我正在使用这个页面 - http://ecmazing.com/cors.html - 制作对此资源的跨域 Ajax 请求:http://hacheck.tel.fer.hr/xml.pl
它适用于 Chrome、Safari 和 Firefox,但不适用于 IE9 和 Opera.
代码:
var pdata = {'textarea': 'test'};$.post('http://hacheck.tel.fer.hr/xml.pl', pdata, function(data, status, xhr) {output.value = xhr.responseText;});
(预期结果是一个 XML 代码字符串.)
自己看看: http://ecmazing.com/cors.html一个>
在 IE9 和 Opera 中,XHR 对象的 error
处理程序执行并传入此错误对象:
<代码>{就绪状态:4,状态:0,状态文本:'错误'}
如您所见,这个错误对象并没有透露太多信息.
如何让它在 IE9 和 Opera 中运行?
查看 cors at whencaniuse 的条目.p>
对于 Internet Explorer,CORS 是在 IE8 和 IE9 中使用 XDomainRequest 对象支持",因此您需要使用备用对象来使用它.
Opera 根本不支持它.
如果你在 Opera 中需要跨域 Ajax,那就使用 JSON-P.
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
It works in Chrome, Safari and Firefox, but doesn't in IE9 and Opera.
The code:
var pdata = {'textarea': 'test'};
$.post('http://hacheck.tel.fer.hr/xml.pl', pdata, function(data, status, xhr) {
output.value = xhr.responseText;
});
(The expected result is an XML code string.)
See for yourself: http://ecmazing.com/cors.html
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.
How can I make it work in IE9 and Opera?
See the entry for cors at whencaniuse.
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.
Opera simply doesn't support it.
If you need cross-domain Ajax in Opera, then use JSON-P.
这篇关于跨域 Ajax 请求在 Opera 和 IE9 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:跨域 Ajax 请求在 Opera 和 IE9 中不起作用?
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01