Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

javascript - Cross-origin Ajax requests don't work in Opera and IE9?

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 Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...