简体   繁体   中英

Cross server AJAX Request - Works in all browsers but IE

Having some problems getting my cross server request to work in IE. Is it possible at all? I've read up on Cross Server Requests, and it seems it depends completely on the browser. If I run the function below in any other browser bar IE, it returns the 'success' function, IE just returns the 'error' function.

My question is, is it possible to get this to return 'success' in IE at all?

I've stripped down my JS code to the following:

jQuery.support.cors = true;

$.getJSON($this.attr('action'))
.error(function() {

    console.log('ERROR');

}).success(function() {

    console.log('success');

});

Thanks, Christian

In order to do cross domain AJAX requests you need to make a JSONP request which you can do by appending 'callback=?' to your url.

log the error message like

$.getJSON($this.attr('action'))
.error(function(jxhr) {

    console.log(jxhr.status+" --- "+jxhr.responseText);

}).success(function(data) {

    console.log('success');

});

what does this console.log(jxhr.status+" --- "+jxhr.responseText); line says in IE also try specifying the contentType like

$.ajaxSetup({
  cache: false,
  crossDomain: true, 
  contentType: "application/json; charset=utf-8"
 });

hope this will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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