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

javascript - AJAX on the iPhone? - Stack Overflow

programmeradmin0浏览0评论

I have a site that I've developed that makes decent use of Javascript, and minimal use of AJAX for a few things. The site worked fine on the iPhone until I added the function to create an HttpRequest handle at which point all Javascript on the iPhone now silently fails. So, I have a few questions.

(1) It seems that AJAX does not work at all on the iPhone. IS this true? If not, how can I modify the HttpRequest create function to accomodate the iPhone?

(2) If AJAX is indeed impossible on the iPhone, is there a way I can modify the function given so that it will fail gracefully on the iPhone, and other scripts on the page will still function?

(3) If this is not true, what do I need to do server side (and is this even possible?) do detect the iPhone, so that I can remove the AJAX code entirely when an iPhone requests the page?

What would also work quite nicely is the ability to use CSS to detect the iPhone as a display device, and act accordingly, similar to what you use with Opera Show. Of course, this wouldn't fix the AJAX issue, but it would be neat. ^_^

Thanks for answers. Several of my customers access the site regularly from the iPhone, and I want my pages to work as much as they possibly can, so I'm willing to modify my code for it, even though I don't have one to test on.

I have a site that I've developed that makes decent use of Javascript, and minimal use of AJAX for a few things. The site worked fine on the iPhone until I added the function to create an HttpRequest handle at which point all Javascript on the iPhone now silently fails. So, I have a few questions.

(1) It seems that AJAX does not work at all on the iPhone. IS this true? If not, how can I modify the HttpRequest create function to accomodate the iPhone?

(2) If AJAX is indeed impossible on the iPhone, is there a way I can modify the function given so that it will fail gracefully on the iPhone, and other scripts on the page will still function?

(3) If this is not true, what do I need to do server side (and is this even possible?) do detect the iPhone, so that I can remove the AJAX code entirely when an iPhone requests the page?

What would also work quite nicely is the ability to use CSS to detect the iPhone as a display device, and act accordingly, similar to what you use with Opera Show. Of course, this wouldn't fix the AJAX issue, but it would be neat. ^_^

Thanks for answers. Several of my customers access the site regularly from the iPhone, and I want my pages to work as much as they possibly can, so I'm willing to modify my code for it, even though I don't have one to test on.

Share Improve this question asked Nov 3, 2008 at 23:15 BlankBlank 7,20813 gold badges51 silver badges71 bronze badges
Add a comment  | 

6 Answers 6

Reset to default 11

Of course the iPhone supports ajax, check out http://developer.apple.com/webapps/ for a BUNCH of resources for developing iPhone webapps. I would recommend using a framework (such as jQuery, or iUI (for ui)) rather than rolling your own ajax functionality, it will already address a lot of the browser quirks and be optimised.

There's no reason AJAX wouldn't work on the iPhone, many of Google's sites/facebook etc use it perfectly well.

Does your AJAX work in Safari/Mac? That's the closest approximation you'll get in a non-mobile environment.

I would imagine there's some bug somewhere in your javascript that you're just not spotting

One useful resource for troubleshooting JavaScript errors like this on the device is the debug console. It should report any parsing errors and can also be used to log messages and exceptions. You can turn it on from Settings > Safari > Developer (scroll to the bottom).

Aax works perfectly on the iPhone, even our most advanced stuff like the Ajax Calendar Starter-Kit works flawlessly on at least my iPhone (3G)

AJAX works very well. If you want a small, simple to use wrapper for AJAX you should check out https://sourceforge.net/projects/quickconnect/. It contains a wrapper called ServerAccessObject found in the ServerAccessObject.js file.

The development blog for QuickConnectiPhone is found at http://tetontech.wordpress.com

I ran into the same problem recently using jQuery, but it was Safari Mobile's behavior at issue. Maybe in your case too.

Shorten the ajax url from "http://the/full/url" to "/just/the/relative/to/root/part"

BTW, it was @pillsbur who originally found the solution here:

http://www.webmasterworld.com/javascript/3382262.htm

发布评论

评论列表(0)

  1. 暂无评论