Search code examples
javascriptcometlong-polling

How to use long-polling from different domain?


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


Solution

  • 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.