我正在尝试显示我通过php文件加载的数据,我已经测试了.php文件,它可以正常工作和显示。我现在正尝试使用JSON将输出解析为我的游戏。
这是我目前的代码,
myGame.leadScreen = function(game) {
this.xhr = new XMLHttpRequest();
this.scoresObject;
this.scoreText;
};
myGame.leadScreen.prototype = {
create: function () {
console.log("in Leaderboard screen");
var scoreStyle = { font: "bold 20pt Arial", fill: "#ffffff", align: "center", stroke: "#444444", strokeThickness: 5 };
this.scoreText = this.add.text(this.world.centerX, this.world.centerY, "High Scores", scoreStyle);
this.scoreText.anchor.setTo(0.5, 0.5);
this.xhr.open("POST", "leaderboard.php", true);
this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.xhr.send();
var self = this;
this.xhr.onload = function() {
if (this.readyState==4 && this.status==200) {
self.scoresObject = JSON.parse(this.resoponseText);
self.scoreText.text = self.scoresObject[0].name + " " +self.scoresObject[0].score;
}
}
}
};
错误来自JSON.parse行,任何指针都赞赏!
由于