函数执行后无法提醒成功消息

时间:2017-12-05 16:20:16

标签: javascript visual-studio-2017

在函数成功执行并发送到数据库后,我无法获得"Thank you for your enquiry!"的警报。我的代码如下:

function addenquiry() {

    Texttitle = $("#Texttitle").val();
    Textenquiry = $("#Textenquiry").val();

    if (validate()) {

        var xmlhttp = new XMLHttpRequest();
        var url = serverURL() + "/addenquiry.php";
        url += "?userid=" + userid + "&Texttitle=" + Texttitle + "&Textenquiry=" + Textenquiry;
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                addEnquiry(xmlhttp.responseText);
            }
        }
        xmlhttp.open("GET", url, true);
        xmlhttp.send();
    }
}

function addEnquiry(response) {
    var arr = JSON.parse(response);
    if (arr[0].result == 1) {
        alert("Thank You for your enquiry!")
    }
    else {
        alert("Sorry please try again");
    }

}

不确定我哪里出错了,标题和消息已成功记录在数据库中,但我没有收到警报,希望得到某人的指导和帮助。谢谢!

0 个答案:

没有答案