【发布时间】:2015-04-26 20:02:39
【问题描述】:
jQuery 应该发送一个 HTTP OPTION 请求来启动 pre-flight CORS,但它总是发送一个 HTTP POST。由于它是一个 POST 浏览器没有获得 Access-Control-Allow-Origin 或 Access-Control-Allow-Method 并且浏览器没有选择,而是 404 响应。
jQuery.ajax('https://domain.com/path', {
crossDomain: true,
data: postData,
error: function(jqXHR, status, errorThrown) {
//whatever
},
success: function(data, status, jqXHR) {
//whatever
},
type: "POST",
xhrFields: {
withCredentials: true
}
});
【问题讨论】:
-
我在处理 CORS 时遇到了困难,这可能会有所帮助:bennadel.com/blog/…
标签: javascript ajax post cors http-options-method