Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Ajax request not working on iPhone device browser

We are in the process of developing an iPhone web app using extensive jquery AJAX calls to extract data from an XML web service. When developing and testing on my Mac on Safari, the calls work beautifully. Problem is, as soon as we test on the iPhone emulator, or on the actual device, we are not getting anything back from the web service.

I have turned on the 'Develop' menu and changed the 'User Agent' to Mobile Safari to see if that makes a difference, but it still works on the PC side of things.

I don't think it is a cross site restriction, as all the ajax calls etc. are made from the same server and port number.

Is there a way we can do javascript debugging on the emulator to see where the call is failing?

Thanks, Devan

like image 408
Devan Avatar asked Sep 30 '09 07:09

Devan


3 Answers

I ran into the same problem.

Check the url: parameter in the object you send to the jQuery.ajax function. Shorten it from "http://the/full/url" to "/just/the/relative/to/root/part"

To me, it seems like a Safari Mobile bug.

like image 123
user238991 Avatar answered Oct 08 '22 04:10

user238991


You can enable the javascript console in Mobile Safari. See the instructions here. It's basically Settings->Safari->Developer->Debug Console. This works on the emulator, and the actual device.

like image 23
Steve K Avatar answered Oct 08 '22 05:10

Steve K


I had the same problem writing an AJAX chat for a website. The problem is the cache. Add this line of code and the problem is solved.

$.ajaxSetup({ cache: false });
like image 1
Kobbe Avatar answered Oct 08 '22 03:10

Kobbe