7

I'm trying to do a long polling using XMLHttpRequest. it works fine on all supporting browsers, but for some reason on safari on iPhone i get the loading indicator for every ajax call, and for long polling thats a bit annoying.

I read that you need to wait until the document is loaded, but it doesn't seam to work. any other known hack to solve it?

Amir
  • 1,219
  • 3
  • 17
  • 31

2 Answers2

1

I have had the same problem , I tried using simple XHRO, hidden iFrames etc , it just does not work on iPhone. It seems to not update the DOM or do anything until the the "entire" document is loaded which, in my example was the duration of the long poll.

The only thing I havent tried is JSONP. Maybe you can try JSONP.

Please let us know if u were able to try JSONP and if it worked or if anything worked at all!

UPDATE: I dont know why this is being marked as an answer, I dont think it is, so please let me know how to make it a comment instead of answer.

Sajjan Sarkar
  • 3,900
  • 5
  • 40
  • 51
  • This is your answer on the question :) but no problem, i'll try it ASAP and give you a feedback here, so thanks for your input :) – Florian Müller Aug 15 '12 at 18:27
  • 1
    I've tried JSONP but this seems not to work for me - I did not even make it to load a source into :/ – Florian Müller Aug 18 '12 at 15:05
  • 2
    @Florian " I did not even make it to load a source into", so you were not able to run the server-returned JS? Can you post some simplified version of your code? I know long-polling is a big pain to make work especially on safari.. I'd really like to know how Etherpad and/or google chat works..I'm suspecting currently on iPhones they still use short-polling periodic AJAX calls..Let me know bro.. – Sajjan Sarkar Aug 21 '12 at 13:51
1

I have had the same problem as well.

Getting long-polling (or any polling really) to work on ALL browsers is a kick in the pants. And especially safari. Goodness.

socket.io is a solution.

khaverim
  • 3,386
  • 5
  • 36
  • 46
  • I can't use this because I'm just allowed to develop on the clientside, so I can only create JavaScript, PHP and HTML-Structures. – Florian Müller Aug 20 '12 at 14:48
  • in this case you should probably consider using jQuery's $.ajax() function to get the job done instead of XMLHttpRequest. I believe it has better compatibility for multiple browsers. You run a simple test in safari with $.ajax() and then build off of it. – khaverim Aug 21 '12 at 03:01