最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Ajax with Cookies - Stack Overflow

programmeradmin3浏览0评论

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: / My username and password aren't in there (although i was testing with a dummy account anyway).

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).

Share Improve this question edited May 27, 2011 at 15:46 Alex asked May 26, 2011 at 23:59 AlexAlex 1,3372 gold badges11 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 23 +50

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)

  1. 暂无评论