Dependent Origination

Iphone app: send cookies for ajax requests

Posted on: December 15, 2010

I am writing an Iphone app right now. When I use it from Chrome or Mobile Safari, everything works out fine. The cookie I saved will be sent up again to the server on subsequent requests. However, when I launch the app from the home screen, everything breaks down and there is never a cookie sent up.

It is very strange since even if launched from the home screen, it is still Mobile Safari that is working behind the scenes. One tricky point I realized up front is that when launching from the home screen, it is file://index.html that is the starting point, in contrast to a well-formed url when executing inside Mobile Safari by me. So the domain is not the same as the domain I am setting the cookies to. However, the server domain is always the same so as long as I set the cookie for my server domain they really should be sent up every time.

This was driving me nuts until yesterday. We actually have an echo server that can dump out the entire HTTP request. There is probably Unix command that can do this and I should dig them out. Anyway we confirmed that the app is not sending up the cookies even though it has it. You can check out under Preferences and Content Settings to see the cookie in Chrome.

Now stackoverflow comes to rescue. There is a fix, which you have to ask PhoneGap to save cookies for AJAX requests. Yes, the initial setting of cookie happens over an AJAX request/response and subsequent AJAX calls will not supply the cookie unless PhoneGap initialization is modified.

Glad this is solved since it is a very annoying and perplexing problem. And to add to the frustration, people use different terms to talk about these things so it is very hard to google., as the environment and the software are so new.


1 Response to "Iphone app: send cookies for ajax requests"


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

December 2010
« Nov   Jan »


  • is reflecting on the past three years and reading the article on divided self aptly showing up at the top of my tweeter feed. 5 months ago
  • is having a nice feeling of connecting dots all over the place. they are now illuminating the same point. 6 months ago
  • Style Transfer is fun! TensorFlow rocks! #WTM17 8 months ago
  • couldn't get over the jetlag, sleeping during the day from seven to four, for days. 10 months ago
  • is emptying trash and happily discovering the available disk space now ranks at 100G+. 11 months ago

Flickr Photos

%d bloggers like this: