0

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.

Teo Mihaila
  • 134
  • 1
  • 2
  • 18
  • 1
    You need to add allow-origin settings for your client domain on server domain. Example: http://stackoverflow.com/questions/20673882/handle-multiple-domains-with-access-control-allow-origin-header-in-apache – Marko Šutija Dec 15 '16 at 14:19
  • Are you in charge of this external `example.com`? if yes then follow @MarkoŠutija's advice... Otherwise do you know PHP coding? If your server allows it then maybe write an app to extract the string and `echo` it back to your game's code. – VC.One Dec 16 '16 at 12:34
  • Thanks, I used @MarkoŠutija's advice. That was the right answer for me – Teo Mihaila Dec 19 '16 at 11:33

0 Answers0