我有以下javascript代码。请注意两行都有大写注释。
出于某种原因,在第一次ajax调用中,如果我提到所有返回的变量'racewon',它会阻止代码执行第一个选项(即当'selected'等于'current'时。当我删除这些引用时'racewon'代码在这里有效。有人可以帮忙吗?
function showe() {
//first make everything invisible again
document.getElementById('current').style.display = 'none';
document.getElementById('details').style.display = 'none';
document.getElementById('new').style.display = 'none';
document.getElementById('delete').style.display = 'none';
// first we take the ID of the person and pass it to our form
var hope = $("#person").val();
var freedome = $.ajax({
method: "GET",
url: "LockInPerson.php",
data: {
thing: hope
}
});
freedome.done(function (msg) {
var racewon = msg["winner"];
var NoOtherAdmin = msg["NoOtherAdmin"];
});
var selected = $("#selector").val();
alert(racewon); //HOW COME WHEN I MENTION THIS RETURNED VARIABLE IT FAILS
if (selected == "current" && racewon != null) { //ALSO IT FAILS WHEN I MENTION THIS VARIABLE HERE
document.getElementById('current').style.display = 'block';
return;
}
if (selected == "details") {
document.getElementById('details').style.display = 'block';
var freedom = $.ajax({
url: "RESPONDERdetails.php",
type: "GET",
dataType: "json",
data: {
thing: hope
}
});
freedom.done(function (msg) {
name = msg["username"];
password = msg["password"];
gender = msg["gender"];
weight = msg["weight"];
$("#DetName").attr("value", name);
$("#DetPassword").attr("value", password);
$("#DetGender").attr("value", gender);
$("#DetWeight").val(weight);
});
return;
}
if (selected == "new") {
document.getElementById('new').style.display = 'block';
return;
}
if (selected == "delete" && NoOtherAdmin == null) {
// this means there is another admin
document.getElementById('delete').style.display = 'block';
//$( "#deleter" ).submit();
return;
}
if (selected == "delete" && NoOtherAdmin != null) {
document.getElementById('makeadmin').style.display = 'block';
return;
}
}