开发者

Using Ajax with Cookies

开发者 https://www.devze.com 2023-03-09 02:53 出处:网络
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 us开发者_开发百科e ajax with cookies. I have gotten it to work without sig

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 us开发者_开发百科e 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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消