Javascript中的xmlhttp.responseText验证不起作用

xmlhttp.responseText validation within Javascript is not working

本文关键字:验证 不起作用 responseText xmlhttp 中的 Javascript      更新时间:2023-09-26

My Below javascript正在从servlet获取resopnse,当我尝试验证时,它正在工作。它无法验证if语句if (xmlhttp.responseText=="1234")

的原因可能是什么

function handleServletPost() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            if (xmlhttp.responseText == "1234") {
                alert("you are star");
            } else {
                alert("alert-->" + xmlhttp.responseText);
            }
        } else {
            alert("Ajax calling error");
        }
    }

xmlhttp.responseText带来了空间,因此我们需要修剪该值。

由于trim不支持纯javascript,所以我使用jquery来实现这一点。