我正在尝试基于responseText
完成一些工作,但即使响应是我所期望的,if语句也不起作用。
window.addEventListener('load', function () {
g("sub").addEventListener('click', function (event) {
event.preventDefault();
var usrnm = g("usrnm").value;
var pass = g("pass").value;
if (usrnm != "" && pass != "") {
g("sub").style.display = "none";
var a = request();
a.open("POST", "/validate/checker.php", true);
a.onreadystatechange = function () {
if (a.readyState == 4 && a.status == 200) {
window.scrollTo(0, 0);
console.log(a.responseText);
g("msg").innerHTML = a.responseText;
if (a.responseText == "nope") {
console.log("tryagain");
} else if (a.responseText == "yup") {
console.log("passed");
} else {
console.log("something else");
}
}
};
a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
a.send("u=" + usrnm + "&p=" + pass);
}
});
});
这是控制台中的输出:
没了
别的东西
我需要的是:
没了
再试一次