Ajax 错误 只发送第一个请求

ajax error only first request is send

本文关键字:第一个 请求 错误 Ajax      更新时间:2023-09-26
$('#show_mess').click(function (){
        $('#dropdown_mess').slideToggle("slow");
        $('#arrow_mess').slideToggle("slow");
        $('#arrow_not').hide("slow");
        $('#dropdown_not').hide("slow");
        function recall(){ setTimeout(function () {  
        xmlhttp = new XMLHttpRequest();
                xmlhttp.open("GET", "http://localhost/ajax/mess_data.php", true);
                xmlhttp.onreadystatechange = function () {
                        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                                document.getElementById('dropdown_mess').innerHTML = xmlhttp.responseText;
                            }       
                    }
                xmlhttp.send();
                document.getElementById('dropdown_mess').innerHTML = "<img class='non_auto' id='ajax_loading' src='img/ajax_loading.gif'></img>";
                recall();
                }, 2000);
            }; 
                recall();
    });

这个函数工作正常,但是当每个ajax调用完成时,我需要colse和重新操作chrome才能工作,在Firefox中工作正常

你已经在使用 Jquery,所以你为什么不试试它的 ajax 函数,如下所示

$.ajax({
    url: "test.html",
    context: document.body
}).done(function() {
    ....
});

您可以在手册中找到更多信息