gpt4 book ai didi

javascript - 得到“未定义ReferenceError”

转载 作者:行者123 更新时间:2023-11-29 19:12:04 26 4
gpt4 key购买 nike

我正在遍历一些测验对象并将结果存储到json变量中。出现"ReferenceError is not defined"错误,不确定原因。

JS代码

// This function will send the quiz results to a PHP script that will store the quiz results.
function storeQuiz(){

//setup the json object
var jsonQuizData = new Object();

// get the learners info
var sl = GetPlayer();
var learnersName = sl.GetVar("usersName");
var learnersEmail = sl.GetVar("usersEmail");
//var learnersCompany = sl.GetVar("usersCompany");

// Loop through the quiz object to go through each quiz question and storying the results.
var arrayLength = g_listQuizzes[g_quizId].arrQuestions.length;
jsonQuizData["questionCount"] = g_listQuizzes[g_quizId].arrQuestions.length;
jsonQuizData["strQuizName"] = g_listQuizzes[g_quizId].strQuizName;
jsonQuizData["nPassingScore"] = g_listQuizzes[g_quizId].nPassingScore;
jsonQuizData["dtmFinished"] = g_listQuizzes[g_quizId].dtmFinished;
jsonQuizData["nMaxScore"] = g_listQuizzes[g_quizId].nMaxScore;
jsonQuizData["nMinScore"] = g_listQuizzes[g_quizId].nMinScore;
jsonQuizData["nPtScore"] = g_listQuizzes[g_quizId].nPtScore;
jsonQuizData["strQuizId"] = g_quizId;
jsonQuizData["strStatus"] = g_listQuizzes[g_quizId].strStatus;
jsonQuizData["usersName"] = learnersName;
jsonQuizData["usersEmail"] = learnersEmail;
//jsonQuizData["usersCompany"] = learnersCompany;

for(var i = 0; i < arrayLength; i++){
jsonQuizData["question"+i] = {
"description" : g_listQuizzes[g_quizId].arrQuestions[i].strDescription,
"strCorrectResponse" : g_listQuizzes[g_quizId].arrQuestions[i].strCorrectResponse,
"strStatus" : g_listQuizzes[g_quizId].arrQuestions[i].strStatus,
"strUserResponse" : g_listQuizzes[g_quizId].arrQuestions[i].strUserResponse,
"nWeight" : g_listQuizzes[g_quizId].arrQuestions[i].nWeight,
"nPoints" : g_listQuizzes[g_quizId].arrQuestions[i].nPoints,
"nQuestionNumber" : g_listQuizzes[g_quizId].arrQuestions[i].nQuestionNumber
}
}

console.log(jsonQuizData);

// Send data to handler
request = new XMLHttpRequest();
request.open("POST", "http://foo.com/quizResultsHandler.php", true);
request.setRequestHeader("Content-type", "application/json");
request.send(JSON.stringify(jsonQuizData));

}


enter image description here

错误从 g_ListQuizzes之后的第14行开始

第14行代码: var arrayLength = g_listQuizzes[g_quizId].arrQuestions.length;

罪魁祸首是: [g_quizId]

有任何想法吗?

最佳答案

未定义jsonQuizData。在放入内容之前,请先使用var jsonQuizData={}对其进行初始化。

为了大声喊叫,人们停止对一切进行严格分类。只需发送JSON并使用JSON。我从未完全理解这种非常奇怪的字符串化方式。

关于javascript - 得到“未定义ReferenceError”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43006329/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com