Mozilla的自己的规范说简单GETPOST应该是本地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);
有帮助吗?

解决方案 2

好了,我不知道是什么都CONTENTTYPES实际工作,但text/plain确实在所有3个浏览器:

var destination = { url: destinationUrl, type: 'POST', success: AjaxSuccess, error: AjaxError,
             contentType: 'text/plain'
        };
var postData={ 'anArray': theArray, 'token': token };
            destination.data=JSON.stringify(postData);

$jq.ajax(destination);

不过到目前为止,我还没有想出什么阻止做任何事情,除了运行,即使返回了505码的成功方法的要求。添加Access-Control-Allow-Origin: *的响应报头解决不希望读出的返回数据的浏览器。

其他提示

我有同样的问题

https://developer.mozilla.org/En/HTTP_Access_Control

说,加密类型必须是text / plain的,或者你需要使用FX4 + 所有访问标头被正确地设置

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top