jQuery.post在IE9上作为HTTP GET发送

时间:2012-10-05 20:29:08

标签: jquery internet-explorer-9

我正在使用jQuery 1.8.2通过jQuery的ajax POST调用一些后端服务器api。后端服务器和网页都在同一个域中。

在我的js文件中,我只是简单地调用$.post('/createAccount',data,function(e) { alert(e); });

在Fiddler中,此请求在IE9中作为GET发送。

GET http://[redacted]/createAccount HTTP/1.1
Accept: */*
Origin: [redacted]
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: [redacted]
Connection: Keep-Alive
Pragma: no-cache

使用Chrome(最新)的同一页面在Fiddler中返回以下内容:

POST http://[redacted]/createAccount HTTP/1.1
Host: [redacted]
Connection: keep-alive
Content-Length: 103
Origin: http://[redacted]
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Referer: http://[redacted]/builder?token=[redacted]
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

email=test123&token=[redacted]&company=tokentest1

以下是使用$ .ajax而不是$ .post(同一问题)的代码:

        $.ajax({
            url : '/createAccount',
            type : 'POST',
            data : obj,
            dataType : 'json',
            cache: 'false',
            success : function(data) {
                if(data.status === 'ok') {

                } else {
                    alert('error');
                }
            }
        });

1 个答案:

答案 0 :(得分:0)

这是一个不确定的时刻。我有一些其他代码可以回退到MSFT的XDomainRequest,在那段代码中它强制所有请求获取,而不是从jQ​​uery选项对象中提取请求类型。