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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

December 2010
« Nov   Jan »


Flickr Photos

%d bloggers like this: