繁体   English   中英

$ .ajax 400错误请求

[英]$.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数据,但是contentTypeapplication/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-Typeapplication/json ,您会将一个简单的跨域请求转换为一个非简单的跨域请求( 在此处了解有关CORS的更多信息 ),这意味着您的浏览器必须发送预检( OPTIONS )请求在您的预期要求之前。 这样做是为了与服务器一起验证是否允许来自其他来源的客户端发出所述请求。

您可以设置的唯一“简单”标头是: AcceptAccept-LanguageContent-LanguageLast-Event-IDContent-Type (如果将其设置为以下之一): application/x-www-form-urlencodedmultipart/form-datatext/plain )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM