IE 8+ XDomainRequest“后”不工作工作、IE、XDomainRequest

2023-09-10 17:03:59 作者:狂拽酷霸吊★

我使用jQuery.XDomainRequest.js(https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest),以支持在IE浏览器的AJAX请求。

它的工作原理非常适合我的GET请求,但POST不工作,它返回一个500。 (我查了一下,它工作在其他浏览器,以便其XDR特定问题)。

我的Ajax调用是这样的:

 无功接触= {};
contact.firstName =ABC;

jQuery.ajax({
     键入:POST,
     网址:contactDetailsUrl,
     数据:联系人,
     数据类型:JSON,
     成功:功能(数据){
                回调(真正的);
              },
     错误:功能(数据){
                警报(目前有麻烦发帖。');
                回调(假);
            }
});
 

这是我与XDomainRequest 1日相遇,我做了我自己的一些研究,但我不知道这是为什么失败。

在此先感谢您的帮助!

编辑:我做了一些调试

我的测试URL =HTTP:/myserver/test/index.php键= 123(这使得跨域请求)

我打印json_en code($ _ GET),我得到:{关键:123} 我打印json_en codeE($ _ POST),我得到:[]

显然,我的职务数据不被发送。

这是我发送的数据行:

  xdr.send(POSTDATA);
 
IE停止工作怎么修复

POSTDATA看起来像出头:

 名字= ABC
 

我在php code看起来像头:

 头(访问控制 - 允许 - 产地:*');
标题(访问控制 - 允许 - 方法:POST,GET,OPTIONS');
头('访问控制,最大年龄:1000);
标题(访问控制 - 允许 - 头:内容类型');
 

解决方案

好了,我的PHP方面的知识比我的XDR知识差。

下面帮助链接

http://social.msdn.microsoft.com/Forums/eu/iewebdevelopment/thread/fe1570a0-8670-450d-90e6-1e03bd338569

我必须使用$ HTTP_RAW_POST_DATA而不是$ _ POST

我会离开的问题最多只是柜面有别人喜欢我就这个问题谁绊倒。

I am using jQuery.XDomainRequest.js (https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest) to support ajax requests in IE.

It works great for my GET request but the POST is not working, it returns a 500. (I checked, it works in other browsers so its XDR specific problem).

My ajax call looks like:

var contact = {};
contact.firstName = "ABC"; 

jQuery.ajax({
     type:  'POST',
     url:   contactDetailsUrl,
     data:  contact,
     dataType: 'json',
     success: function(data) {
                callback(true);
              },
     error: function(data) {
                alert('Currently having trouble posting.');
                callback(false);
            }
});

This is my 1st encounter with XDomainRequest, I did some research of my own, but I have no clue why is this failing.

Thanks in advance for your help!!!

EDIT: I did some debugging.

My test url = "http:/myserver/test/index.php?key=123" (This makes a cross-domain request)

I printed json_encode($_GET) , I get : {"key":"123"} I printed json_encodee($_POST), I get : [].

Clearly my post data is not being sent.

This is the line that sends my data:

xdr.send(postData);

postData looks somethings like:

"firstName=ABC"

My headers in the php code look like :

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');

解决方案

Ok, So my knowledge of php is worse than my XDR knowledge.

The link below helped

http://social.msdn.microsoft.com/Forums/eu/iewebdevelopment/thread/fe1570a0-8670-450d-90e6-1e03bd338569

I have to use $HTTP_RAW_POST_DATA instead of $_POST.

I'll leave the question up just incase there is someone else like me who stumbles upon this question.

 
精彩推荐
图片推荐