問題描述
我正在使用這個頁面 - 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 中不起作用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!