I have a php file on a server, which just prints random numbers.
I want to get these numbers by using XMLHttpRequest from another domain.
How can I do this?
I have a php file on a server, which just prints random numbers.
I want to get these numbers by using XMLHttpRequest from another domain.
How can I do this?
You can't.
XHR is subject to the same origin policy. There is ongoing work to design and implement systems to allow cross-domain XHR, but the current state of those (the lack of browser support in particular) make it impractical for any real project.
The usual method to work around this is to implement the system using JSON-P instead of XHR.
You can implement CORS (Cross-Origin Resource Sharing) on your server.
The current versions of Google Chrome, Firefox and Safari support it now.
The next versions of Opera and Internet Explorer also support it but have not been released yet as of the beginning of March 2012.