IE中的$ .ajax POST调用问题用于跨域($.ajax POST call issue in IE for cross domain)

编程入门 行业动态 更新时间:2024-10-21 09:46:41
IE中的$ .ajax POST调用问题用于跨域($.ajax POST call issue in IE for cross domain)

所有,这可能是经常重复的问题..但我已经在这一天超过一天..到目前为止它令人失望和令人沮丧...... :(

function (url, requestData) { var jqryXHR = $.ajax({ type: 'POST', url: anotherDomainurl, //contentType: 'application/json; charset=UTF-8', data: { requestParams: requestData } });

}

这在FF和Chrome中运行良好但在IE上没有。在IE中,调用本身没有被触发。我该怎么办才能使它工作......并且要求是用POST进行调用。

我的服务器端代码是java和am设置

header('Access-Control-Allow-Origin','* .anotherDomain.com');

问候

All, This could be oft-repeated question..but i have been at this for over a day..and so far its disappointing and frustrating.. :(

function (url, requestData) { var jqryXHR = $.ajax({ type: 'POST', url: anotherDomainurl, //contentType: 'application/json; charset=UTF-8', data: { requestParams: requestData } });

}

This works fine in FF and Chrome but not on IE.In IE the call itself is not getting triggered .What should i do to make it work...And requirement is to make call with POST.

My server side code is java and am setting

header('Access-Control-Allow-Origin', '*.anotherDomain.com');

Regards

最满意答案

使用jsonp。 它提供了一种从不同域中的服务器请求数据的方法。

http://remysharp.com/2007/10/08/what-is-jsonp/

Was able to solve the problem finally...

For IE, we would have to use the

Cross-domain Request (XDR) for Cross Domain call..instead of XMLHttpRequest

Refer : http://msdn.microsoft.com/en-us/library/dd573303%28v=vs.85%29.aspx

There are some restrictions when using XDR which can be viewed @

http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

if (window.XDomainRequest) { var xdr = new XDomainRequest(); xdr.open("POST", url); xdr.onload = function () {}; xdr.onerror = function() {}; xdr.onprogress = function() {}; xdr.send("requestData="+jsonData); } else{ jQuery.support.cors = true; var jqXHR = $.ajax({ type : 'POST', url : url, crossDomain: true, data : { requestData : jsonData } }); }

Also at server end, the response should have headers added

Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers

更多推荐

本文发布于:2023-08-07 19:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465578.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:call   POST   ajax   domain   cross

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!