Вопрос

I try to save a backbone model with model.save(), I gave the urlRoot, and I'm waiting for a POST call. I have a REST service on another subdomain which is waiting for the request.

I got these request headers by the model.save().

OPTIONS /user HTTP/1.1
Host: rest.secret.loc
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://members.secret.loc
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

Sy mentioned that this is a preflight request, so I should respond with the following headers:

HTTP/1.1 200 OK
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Type: text/html
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: PHP/5.3.8, ASP.NET
access-control-allow-origin: http://members.secret.loc
Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS
Date: Fri, 17 May 2013 01:18:21 GMT
Content-Length: 0

I tried out, but this is not working, the browser does not send another request to the server :S :S :S :S :S

How to fix it? Is this a backbone bug?

Это было полезно?

Решение

I tried out with Chrome, and in chrome console appears what in firebug not: The content-type header is not allowed. So I modified the web.config file:

       <add name="Access-Control-Allow-Headers" value="Content-Type" />

This fixed the problem.

Btw it still sends the preflight, so I put this code on server side:

if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
    exit;

So it won't mess up everything...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top