我在调用goToXProfile(targetusername)时出错,它引发了异常“Microsoft JScript 运行时错误:'test' 未定义”,其中 'test' 是传递的targetusername参数。
这是我的代码
function getQuestionByID() {
var QuestionID = localStorage["QuestionID"];
var postData = { 'Function': 'GetQuestionByID', 'QuestionID': questionID, 'UserID': userID };
$.ajax({
beforeSend: function () { $.mobile.showPageLoadingMsg(); }, //Show spinner
complete: function () { $.mobile.hidePageLoadingMsg() }, //Hide spinner
type: "GET",
url: serviceUrl + "/Questions.aspx",
data: postData,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
jsonp: 'jsoncallback',
success: function (result) {
viewQuestion(result);
},
error: function (msg) {
alert('Sorry, a problem happened');
}
});
}
function viewQuestion(data) {
var QuestionData = (typeof data) == 'string' ? eval('(' + data + ')') : data;
if (data !== undefined || data !== "0") {
$('#QuestionChosen').empty();
var text = '<li data-role="list-divider" class="vote-list-divider">' + QuestionData.Pt_Title + '<span onclick="voteForQuestion(1);" id="voteUp" class="ui-li-count vote">+ ' + QuestionData.Likes + '</span><span onclick="voteForQuestion(-1);" id ="voteDown" class="ui-li-count vote">- ' + QuestionData.Dislikes + '</span></li><li><a rel="external" onclick = "editQuestionChecking();"><h3>' + QuestionData.Sub_Name + '</h3><p>' + QuestionData.Pt_Body + '</p><a onclick="goToXProfile(' + QuestionData.SU_Username + ');"> CreatedBy: ' + QuestionData.SU_Username + '</a></a><a id="bookmarked"onclick="bookmarkQuestion();" data-icon="star" data-theme = "b"></a></li> ';
$('#QuestionChosen').append(text);
$("#QuestionChosen").listview('refresh');
var QoriginalVoteValue = QuestionData.OriginalVoteValue;
if (QoriginalVoteValue == 1) {
$('#voteUp').addClass("up-vote-active");
}
else if (QoriginalVoteValue == -1) {
$('#voteDown').addClass("down-vote-active");
}
bookmarked = QuestionData.Bookmarked
if (bookmarked) {
$('#bookmarked').attr("data-theme", "a").removeClass("ui-btn-up-b").addClass("ui-btn-up-a");
}
viewQuestionAnswers(localStorage["QuestionID"]);
}
else {
alert("Sorry, this question can't be accessed, it's either deleted or you don't have permission to access it");
}
}
function goToXProfile(x) {
getQuestionUser();
localStorage["XUserID"] = localStorage["AskerID"];
localStorage["XUsername"] = x;
alert("XUserID = " + localStorage["XUserID"]);
alert("XUsername = " + localStorage["XUsername"]);
}
有什么建议么?提前致谢。