简体   繁体   English

跨服务器AJAX请求 - 适用于除IE之外的所有浏览器

[英]Cross server AJAX Request - Works in all browsers but IE

Having some problems getting my cross server request to work in IE. 遇到一些问题让我的跨服务器请求在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. 如果我在任何其他浏览器栏IE中运行下面的函数,它将返回'success'函数,IE只返回'error'函数。

My question is, is it possible to get this to return 'success' in IE at all? 我的问题是,是否有可能让它在IE中恢复“成功”?

I've stripped down my JS code to the following: 我已将我的JS代码删除到以下内容:

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=?' 为了执行跨域AJAX请求,您需要通过附加'callback =?'来发出JSONP请求。 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); 这个console.log(jxhr.status+" --- "+jxhr.responseText);是什么console.log(jxhr.status+" --- "+jxhr.responseText); line says in IE also try specifying the contentType like line在IE中说也尝试指定contentType类的

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

hope this will help 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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