Mozilla的自己specification說簡單GET
或POST
應該是本地CORS的無預檢但到目前爲止一切POST
嘗試我做已經導致了OPTIONS
頭走出去。當我將其從POST
更改爲代碼立即發送一個適當的GET
請求,以便跨網站部分工作正常。爲什麼CORS似乎不適用於POST?
下面是我在做什麼在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);