Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone & Slim PHP - Access-Control-Allow-Headers - Can GET information, can't POST it?
    primarykey
    data
    text
    <p>I'm using Backbone and the Slim PHP framework. I'm trying to post information to my API, however Access-Control-Allow-Headers keeps causing me problems...</p> <p>My console reads: </p> <pre><code> OPTIONS http://api.barholla.com/user/auth 405 (Method Not Allowed) zepto.min.js:2 XMLHttpRequest cannot load http://api.barholla.com/user/auth. Request header field Content-Type is not allowed by Access-Control-Allow-Headers. </code></pre> <p>My headers read:</p> <pre><code>Request URL:http://api.barholla.com/user/auth Request Method:OPTIONS Status Code:405 Method Not Allowed Request Headersview source Accept:*/* Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Access-Control-Request-Headers:origin, content-type, accept Access-Control-Request-Method:POST Connection:keep-alive Host:api.barholla.com Origin:http://localhost Referer:http://localhost/barholla/app/ User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4 Response Headersview source Access-Control-Allow-Origin:* Allow:POST Connection:close Content-Type:application/json Date:Thu, 08 Nov 2012 16:12:32 GMT Server:Apache Transfer-Encoding:chunked X-Powered-By:Slim X-Powered-By:PleskLin </code></pre> <p>My headers in my slim index.php file are:</p> <pre><code>$res = $app-&gt;response(); $res-&gt;header('Access-Control-Allow-Origin', '*'); $res-&gt;header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS"); </code></pre> <p>To handle the post data:</p> <pre><code>$app-&gt;post('/user/auth', function () use ($app) { //code here }); </code></pre> <p>In my javascript (i'm using the backbone framework) my code is:</p> <pre><code> App.userAuth = new App.UserAuthModel({ username: $('#username').val(), password: hex_md5($('#password').val()) }); App.userAuth.save({}, { success: function(model, resp) { console.log(resp); }, error: function(model, response) { console.log(response); } }); </code></pre> <p>Any help would be much appreciated, I've been stuck on this for ages!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload