jQuery POST not sending Content-Type on IE10

自作多情 提交于 2019-12-08 10:00:41

问题


I'm using jQuery 1.9.1 and Internet Explorer Version 10.0.9200.16686, Update Version 10.0.9 (KB2870699), on Windows 7 64-bit.

When using $.ajax to POST, the Content-Type header is not being sent. It works fine in Chrome and other browsers, and I believe used to work fine before on IE10 so I suspect some update to IE10 caused an issue.

I can also manually create an XMLHttpRequest and send a request, so I'm assuming it must be a bug in jQuery that's the real issue? I tried upgrading to 1.10.2, but get the same problem.

I have the contentType set using $.ajaxSetup:

$.ajaxSetup({
    contentType: 'application/json; charset=utf-8',
    context: document.body,
    dataType: 'json',
    accepts: 'application/json',
    processdata: true,
    cache: false,
    crossDomain: true,
    xhrFields: { withCredentials: true }
});

I've also tried explicitly setting it as part of the $.ajax options.

var options = {
    url: basePath + 'login',
    type: 'POST',
    dataType: 'json',
    contentType: 'application/json',
    data: JSON.stringify({
        UserName: username,
        Password: password,
        RememberMe: rememberMe || false
    })
};
return $.ajax(options).then(...);

Any ideas how to fix it will be appreciated.

Note: we were initially using CORS, hence the reason for the xhrFields and crossDomain settings, but are currently hosting everything on the same domain because of issues with IE8 and IE9 and XDomainRequest.


回答1:


It appears that we still had the xdr.js script included to enable CORS on IE, which was causing this issue.



来源:https://stackoverflow.com/questions/19158164/jquery-post-not-sending-content-type-on-ie10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!