- Home /
Problem with Javascript calling PHP pages in WebGL
I seem to be having issues with calling PHP pages from Unity when compiled into WebGL (HTML5). I have followed multiple tutorials online with posting and retreiving high scores.
All works fine when testing in Unity, it just fails after compiling. Can anyone help?
Just in case, here is the most basic script (I've written about 10 variations to try and see why this is not working). Which, as I say, works fine in Unity, just not in compiled form:
var ScoreList : GameObject;
function Start ()
{
var highscoreURL = "myurl.net/display.php";
var hs_get = new WWW("http://"+highscoreURL);
yield hs_get;
// and check for errors
if (hs_get.error == null)
{
// request completed!
var help = hs_get.text;
ScoreList.GetComponent.<Text>().text = help;
}
else
{
// something wrong!
Debug.Log("WWW Error: "+ hs_get.error);
ScoreList.GetComponent.<Text>().text = "LOADING FAILED";
}
}
So When Running in Unity, my PHP returns the Hiscores into my text box. When run from browser when compiled. I get "LOADING FAILED" in the text box. The hs_get.error just returns "Unknown Error".
Oh, and I can run the PHP scripts directly from a browser without any issues.
Are the php scripts from the same origin? (same server/domain)
Interesting point.
Do you mean between testing and live? If so then the answer is YES.
If however, you mean is the WebGl in the same server/domain as the php scripts then the answer is no.
Could this be the cause?
Your answer
Follow this Question
Related Questions
Best way to emulate Swift String Interpolation in UnityScript? 1 Answer
UI Text showing weird string value? 1 Answer
Scripting Help: Timer Problem 0 Answers
Scripted tank track bones behave strange 0 Answers
Building on android. 1 Answer