xmlhttprequest - 为什么 CORS 似乎不适用于 POST?

标签 xmlhttprequest w3c cors

Mozilla 自己的 specification说简单 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);

最佳答案

我也有同样的问题

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

说 enctype 必须是 text/plain 或者你需要使用 Fx4+
必须正确设置所有访问 header

关于xmlhttprequest - 为什么 CORS 似乎不适用于 POST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563081/

相关文章:

c# - HttpResponse 中的 Angular 6 空 header 数组

html - 无声自动播放视频

javascript - 如何在 Sharepoint Online 中启用 CORS

node.js - AS3可以从 header 识别CORS权限吗?

javascript - HTML 文件的总大小(包括其中图像的大小)

jquery - jQuery.ajax() 跨源 XHR 未返回 Etag header

java - 有什么方便的方法可以将 w3c Document 转换为 jsoup one

css - 为什么我们不能在 col 标签中设置颜色?

jquery - 如何使用CORS访问Flipkart API?

json - 从 map 中提取数据位置