Mozilla 自己的 specification说简单 GET
或 POST
应该是没有预检的原生 CORS,但到目前为止每个 POST
我所做的尝试导致了 OPTIONS
头出去。当我从 POST
改变它时要立即获取代码,请发送正确的 GET
请求所以跨站点部分工作正常。
这是我在 Firefox 中所做的精简示例:
var destinationUrl = 'http://imaginarydevelopment.com/postURL';
var invocation = new XMLHttpRequest();
if (invocation) {
invocation.open('POST', destinationUrl, true);
//tried with and without this line
//invocation.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
invocation.onreadystatechange = (function Handler() {
if (invocation.readyState == 4)
alert('Request made');
});
invocation.send(/* tried with and without data*/);
}
这是我已经在 chrome 和 IE 中工作的内容:
var destinationUrl = 'http://imaginarydevelopment.com/postURL';
var destination = { url: destinationUrl, type: 'POST', success: AjaxSuccess, error: AjaxError,
dataType: 'text', contentType: 'application/x-www-form-urlencoded'
};
destination.data = { 'rows': rowList, 'token': token };
$jq.ajax(destination);
最佳答案
我也有同样的问题
https://developer.mozilla.org/En/HTTP_Access_Control
说 enctype 必须是 text/plain 或者你需要使用 Fx4+
必须正确设置所有访问 header
关于xmlhttprequest - 为什么 CORS 似乎不适用于 POST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563081/