[英]$.ajax 400 Bad Request
目标是通过ajax将对象发送到另一台服务器,该服务器是我为CORS设置的,这是$.ajax
片段:
$.ajax "#{config.url_root}/register",
type: "POST"
data: model.attributes
dataType: "json"
success: (data, text, xhr) -> console.log data, text, xhr
error: (xhr, text, error) -> console.log text, error
正确地过POSTS
数据,但是contentType
为application/x-www-urlencoded; charset utf-8
application/x-www-urlencoded; charset utf-8
; 当我将contentType
的值显式设置为“ application / json; charset = utf-8”时, it executes with a request method of
OPTIONS?! , it executes with a request method of
?! and fails to deliver the data (
?! and fails to deliver the data (
404未找到`)
通过将XMLHttpRequest的Content-Type
为application/json
,您会将一个简单的跨域请求转换为一个非简单的跨域请求( 在此处了解有关CORS的更多信息 ),这意味着您的浏览器必须发送预检( OPTIONS
)请求在您的预期要求之前。 这样做是为了与服务器一起验证是否允许来自其他来源的客户端发出所述请求。
您可以设置的唯一“简单”标头是: Accept
, Accept-Language
, Content-Language
, Last-Event-ID
和Content-Type
(如果将其设置为以下之一): application/x-www-form-urlencoded
, multipart/form-data
或text/plain
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.