Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Ajax with Cookies

I am trying to create a drag and drop interface for my website that integrates with Imgur. The problem is that I am trying to use ajax with cookies. I have gotten it to work without signing in, but I need the pictures to be under my account. In theory my code should work, but in practice for some reason the ajax requests/cookies aren't working. What am I doing wrong? Thanks :D

My code: http://jsfiddle.net/msm595/9arFd/ My username and password aren't in there (although i was testing with a dummy account anyway).

like image 807
Alex Avatar asked May 26 '11 23:05

Alex


1 Answers

https://developer.mozilla.org/en/http_access_control#Requests_with_credentials

You are using cross domain plus credentials. Then the server has to response with:

Access-Control-Allow-Origin: http://jsfiddle.net/msm595/9arFd/

and not with:

Access-Control-Allow-Origin:*

Wildcards are not allowed in this case. You may want to test with Chrome, it shows both headers and gave me this message:

XMLHttpRequest cannot load http://api.imgur.com/2/signin. Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.`

That's all I can say, imgur has to explicitly allow your JS solution. You may need a piece of code running on server's side not having cross domain issues.

like image 140
Torsten Becker Avatar answered Nov 08 '22 10:11

Torsten Becker