如何解决尝试使用 Json 响应发布时,IE 11 获得“405 Method Not Allowed”
尝试使用 JSON 响应发出 Post 请求时,IE 11 会收到 405 错误。相同的代码适用于 Chrome 和 Firefox。
function createToken() {
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open('POST','ssgtokenprovider/createtoken',true);
// If specified,responseType must be empty string or "text"
xhr.responseType = 'text';
xhr.setRequestHeader('Content-Type','application/json');
var data = {tokenType: document.getElementById("SPX_TOKEN_TYPE").value,username: document.getElementById("SPX_TOKEN_USER").value,password: document.getElementById("SPX_TOKEN_PASSWORD").value
};
xhr.onreadystatechange = function() {
document.getElementById("token").innerHTML = JSON.stringify(JSON.parse(xhr.responseText),null,2);
};
xhr.send(JSON.stringify(data));
}
我试过删除
xhr.setRequestHeader('Content-Type','application/json');
根据对 IE 11 Responds with "405 Not Allowed" to XMLHttpRequest 的评论,但它不起作用,并在 Chrome/Firefox 上破坏了它。
如何绕过不支持 json 作为 responseType 的 IE 11?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。