简体   繁体   English

Ajax调用不成功

[英]Ajax call not successful

I am making a javascript function call on onclick of any checkbox like this: 我正在对任何复选框的onclick进行javascript函数调用,如下所示:

function getPGCountList(pageNo) {
    var url = "someJsp.jsp?" + pageNo;
    alert(1);
    if (window.XMLHttpRequest) {
        alert(2);
        xmlhttp = new XMLHttpRequest();
    } else {
        alert(3);
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    alert(4);
    xmlhttp.onreadystatechange = function () {
        alert(5);
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            alert(6);
            document.getElementById("searchForPage").innerHTML = xmlhttp.responseText;
        }
    };
    alert(7);
    xmlhttp.open("GET", url, true);
    alert(8);
    xmlhttp.send();
}

The alert output I am getting is at my hosted site: 我得到的警报输出在我的托管站点上:

1-2-4-7-5-8-5-5-5

But in my local system it is: 但是在我的本地系统中是:

1-2-4-7-5-8-5-5-5-6

I need to execute alert 6 also to change the content. 我还需要执行警报6来更改内容。 I am not sure where is the problem? 我不确定问题出在哪里?

Your code looks fine to me. 您的代码对我来说很好。 Check the path to someJsp.jsp It's obviously not returning a normal response from the ajax call otherwise it would enter your if block and fire alert 6. 检查someJsp.jsp的路径很显然,它没有从ajax调用返回正常响应,否则它将进入if块并触发警报6。

Just a thought too, but if you alert xmlhttp.readyState and xmlhttp.status maybe it'll help you find your problem. 也是一个想法,但是如果您警告xmlhttp.readyState和xmlhttp.status,它可能会帮助您找到问题。 IF they are undefined, or refer to an object that is undefined, then your new XMLHttp requests failed. 如果它们是未定义的,或者引用的是未定义的对象,则新的XMLHttp请求将失败。 IF they give you results, you can see what the responses mean 如果他们给您结果,您就可以看到答复的含义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM