I am trying to create a HTML5 game in Flash and I am stuck at getting a string from another page (so, all the content of the page as a string, let's say I want the content from example.com
), on a different domain. So how can I get data from another page while my game runs in the browser? So far I tried with XMLHttpRequest. I wrote the following code in the first layer of my Flash project:
url = "http://www.example.com/";
GetCustomerInfo();
var xmlHttp = null;
function GetCustomerInfo() {
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = ProcessRequest;
xmlHttp.open( "GET", url, true );
xmlHttp.send( null ); }
function ProcessRequest() {
if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 )
{
if ( xmlHttp.responseText == "Not found" )
{
//action
}
else
{
//action
}
} }
This is my code so far, and it is not working. In the browser console I get the following error: **XMLHttpRequest cannot load http://www.example.com/ No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.**
I don't mind if I receive a totally different method of solving this, different than the one I used.