Javascript 意外的令牌错误JSON
我目前正在尝试显示通过php文件加载的数据,我已经测试了.php文件,它可以正常工作并显示。我现在尝试使用JSON解析游戏的输出 这是我目前的代码Javascript 意外的令牌错误JSON,javascript,php,json,xmlhttprequest,Javascript,Php,Json,Xmlhttprequest,我目前正在尝试显示通过php文件加载的数据,我已经测试了.php文件,它可以正常工作并显示。我现在尝试使用JSON解析游戏的输出 这是我目前的代码 myGame.leadScreen = function(game) { this.xhr = new XMLHttpRequest(); this.scoresObject; this.scoreText; }; myGame.leadScreen.prototype = { create: function (
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行,欢迎使用任何指针
谢谢错误可能来自您的服务器,特别是它生成的响应。查看该回答以查找错误,或将其添加到您的问题中。您得到的错误是什么?这可能有助于帮助您;)