当我跑我的JavaScript我得到这个错误:遗漏的类型错误的JavaScript Canot读取属性“”用户名”
KinveyRequester.js:23 Uncaught TypeError: Cannot read property 'username' of undefined
而且我不知道怎么解决它
代码:
function registerUser(e) {
registerAjax(e);
registerSuccess();
// window.location = "Items.html";
}
function registerSuccess(userInfo) {
saveAuthInSession(userInfo);
showInfo('User registration successful.');
}
function saveAuthInSession(userInfo) {
sessionStorage.setItem("username", userInfo.username);
sessionStorage.setItem("authToken", userInfo._kmd.authtoken);
$("#loggedInUser").text("Welcome, " + userInfo.username);
}
function registerAjax(e) {
e.preventDefault();
let userData = {
username: $("#username").val(),
password: $("#password").val()
};
$.ajax({
method: "POST",
url: kinveyBaseUrl + "user/" + kinveyAppKey + "/",
headers: kinveyAppAuthHeaders,
data: userData,
success: registerSuccess,
error: handleAjaxError
});
}
考虑把你的代码放到一个掉毛的工具。你有一些语法错误。 – evolutionxbox
似乎你从来没有在这里调用'saveAuthSession'? –
它应该是userData,而不是userInfo。 – pshep123