我在前面使用Backbone和jQuery,并使用Python / Tornado创建API。由于我的API位于http://api.domain.com且网站位于http://domain.com,因此当我尝试保存Backbone模型时,它首先执行OPTIONS请求。问题是它说“加载取消”,即使服务器返回了有效的响应。
请求标题:
OPTIONS /user/xdfr456890sd HTTP/1.1
Host: api.domain.com
Connection: keep-alive
Access-Control-Request-Method: PUT
Origin: http://domain.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
Access-Control-Request-Headers: origin, content-type, accept
Accept: */*
Referer: http://domain.com/settings
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
响应标题:
HTTP/1.1 200 OK
Date: Thu, 06 Dec 2012 05:41:51 GMT
Content-Type: text/plain
Content-Length: 0
Connection: keep-alive
Server: TornadoServer/2.4
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://domain.com
Access-Control-Allow-Methods: PUT, DELETE, POST, GET
Access-Control-Allow-Headers: Origin, Accept-Language, Accept-Encoding, Accept-Charset, Access-Control-Request-Headers, X-Scheme, Connection, Accept, User-Agent, Access-Control-Request-Method, Host, Referer, X-Real-Ip
我错过了什么吗?做错了什么?我已经尝试了响应头及其值的每种可能组合。 Access-Control-Allow-Origin
是Origin
请求标头的任何内容。
答案 0 :(得分:1)
您已列出方法
Access-Control-Allow-Methods: PUT, DELETE, POST, GET
但是,您使用上面未列出的OPTIONS
方法拨打电话