0

I would like to use longpolling, if the websocket isn't avaiable. But how to make it, if the server, and the website isn't located in the same domain?

Sorry for my bad english. If you have any idea, then share it with me.

Thanks in advance

Danny Fox
  • 38,659
  • 28
  • 68
  • 94
  • 1
    Have you tried something that failed? Cross-domain long-polling is exactly the same as cross-domain regular polling (except for how long the request takes), so the same solutions apply (CORS, JSONP, etc.). – cheeken Feb 13 '12 at 17:10
  • Yes, I tried, but xmlhttp request doesn't works cross domain: 'Uncaught exception: ReferenceError: Security violation' – Danny Fox Feb 13 '12 at 17:13
  • 2
    Indeed, you cannot perform AJAX requests across domains. You need to use a different approach, such as the ones I mentioned. My point is that your problem is not specific to long-polling. See http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain – cheeken Feb 13 '12 at 17:17

1 Answers1

2

Danny,

Right now (until cross-domain messaging is better supported), you will need to utilize a dynamic script tag long polling method whereby you dynamically add a script tag to the dom instead of doing a traditional ajax request (ex: document.createElement("script")). You can determine if the page has loaded by using the onreadystatechange event that is fired when the script has successfully been loaded.

Osmaan Shah
  • 345
  • 2
  • 8