我正在尝试制作个人资料页面。但是,截至目前,我的应用的个人资料用户ID和电子邮件未在我的网页上显示。检查控制台时,我的个人资料没有错误。有什么方法可以解决这个问题吗?
的Javascript
$(document).ready(function () {
getProfile(); //execute getProfile() to get user's profile
});
//Profile Section
function getProfile() {
var url = serverURL() + "/getuser.php"; //execute getprofile.php
var JSONObject = {
"userid": localStorage.getItem("userid") //provide userid to execute getprofile.php
};
$.ajax({
url: url,
type: 'GET',
data: JSONObject,
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (arr) {
_getProfileResult(arr); //successful call to getprofile.php execute _getProfileResult()
},
error: function () {
validationMsg();
}
});
}
function _getProfileResult(arr) {
for (var i = 0; i < arr.length; i++) {
htmlstring = "<img src='" + serverURL() + "/images/" + arr[i].imagefile + "' height='100'><div>";
$("#txtProfileUsername").html(arr[i].userID);
$("#txtProfileEmail").html(arr[i].email);
$("#profileimage").append(htmlstring);
}
$("#txtProfileUsername").html("User ID: " + userid); //update <div> with userid
$("#txtProfileEmail").html("Email: " + email); //update <div> with email
$("#txtAddress").val(address); //update <div> with address
$("#imgProfilePicture").attr("src", serverURL() + "/images/" + profileimage + "_s"); //update <img> with image
}
HTML
<div role="main" class="ui-content" id="main-ui">
<div id="profileimage"></div>
<div id="txtProfileUsername"></div>
<div id="txtProfileEmail"></div>