【发布时间】:2020-05-21 17:21:05
【问题描述】:
我在 asp.net core mvc 上做一个项目,我在 javascript 文件中有一个问题。我有一个名为“parsedJson”的对象,其中包含几个参数(如“状态”)。当我运行该项目时,我遇到了这个问题。我在这样的函数中描述了 parsedJson
function checkStatus(myID) {
$.ajax(
{
url: '/MemoryGame/checkStatus',
type: 'POST',
data: { 'ID': myID },
dataType: 'json',
success: function (response) {
var parsedJson = response;
if (parsedJson.ifQuit == "True") {
OpponentQuit(parsedJson.myID);
}
else {
else if (parsedJson.status == "Won") {
FunctionName(parsedJson);
}
else if (parsedJson.status == "Lost") {
FunctionName(parsedJson);
}
else if (parsedJson.status == "Tie") {
FunctionName(parsedJson);
}
}
},
error: function (errorThrown) {
console.log(errorThrown);
ConnectionChanged();
}
});
}
function FunctionName(parsedJson)
{
...
if (parsedJson.status == "Won") {
YouWon(parsedJson.myID);
}
else if (parsedJson.status == "Lost") {
YouLost(parsedJson.myID);
}
else if (parsedJson.status == "Tie") {
GameTied(parsedJson.myID);
}
}
顺便说一句,parsedJson 文件不为空,每次运行时状态都有自己的值。 谁能建议我在函数中定义对象的正确方法?
【问题讨论】:
-
请将您的代码发布为文本,而不是图像,并包含定义
parsedJson的代码部分。 -
我在帖子中添加了它们
-
我是根据现有代码测试的,没有报错。你的js文件的完整代码是什么?
-
@XueliChen 我也看不懂,因为这段代码适用于这个项目的另一个文件
标签: javascript asp.net-core model-view-controller