【发布时间】:2011-02-03 12:28:41
【问题描述】:
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);
【问题讨论】:
标签: xmlhttprequest w3c cors