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:

WordPress.com Logo

You are commenting using your WordPress.com 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
M T W T F S S
« Nov   Jan »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Twitter

  • is emptying trash and happily discovering the available disk space now ranks at 100G+. 4 days ago
  • is looking at other people's intentions, not their capabilities, and feeling much happier every day :) 11 months ago
  • is planning on how to spend the next two weeks until the new year, at home. 11 months ago
  • is going to have human company for Thanksgiving; a rare event for the past like twenty years. 1 year ago
  • living by myself again; a strange feeling in a bustling city with thirteen million people 1 year ago

Flickr Photos

IMG_3517

IMG_3515

IMG_3505

IMG_3497

IMG_3261

IMG_3260

IMG_3255

IMG_2736

IMG_2733

IMG_2629

More Photos
%d bloggers like this: