Javascript ajax错误-仅发送第一个请求 $('show#u mess')。单击(函数(){ $('dropdown'u mess')。滑动切换(“slow”); $('arrow_mess')。滑动切换(“slow”); $('arrow_not')。隐藏(“slow”); $(“#下拉菜单_not”).hide(“slow”); 函数调用(){setTimeout(函数(){ xmlhttp=新的XMLHttpRequest(); open(“GET”http://localhost/ajax/mess_data.php“,对); xmlhttp.onreadystatechange=函数(){ if(xmlhttp.readyState==4&&xmlhttp.status==200){ document.getElementById('dropdown_mess')。innerHTML=xmlhttp.responseText; } } xmlhttp.send(); document.getElementById('dropdown_mess')。innerHTML=“”; 召回(); }, 2000); }; 召回(); });
这个函数工作得很好,但是每次ajax调用完成后,我需要关闭并重新操作chrome才能工作,在firefox中工作得很好。您已经在使用Jquery了,为什么不试试下面的ajax函数呢Javascript ajax错误-仅发送第一个请求 $('show#u mess')。单击(函数(){ $('dropdown'u mess')。滑动切换(“slow”); $('arrow_mess')。滑动切换(“slow”); $('arrow_not')。隐藏(“slow”); $(“#下拉菜单_not”).hide(“slow”); 函数调用(){setTimeout(函数(){ xmlhttp=新的XMLHttpRequest(); open(“GET”http://localhost/ajax/mess_data.php“,对); xmlhttp.onreadystatechange=函数(){ if(xmlhttp.readyState==4&&xmlhttp.status==200){ document.getElementById('dropdown_mess')。innerHTML=xmlhttp.responseText; } } xmlhttp.send(); document.getElementById('dropdown_mess')。innerHTML=“”; 召回(); }, 2000); }; 召回(); });,javascript,jquery,ajax,Javascript,Jquery,Ajax,这个函数工作得很好,但是每次ajax调用完成后,我需要关闭并重新操作chrome才能工作,在firefox中工作得很好。您已经在使用Jquery了,为什么不试试下面的ajax函数呢 $('#show_mess').click(function (){ $('#dropdown_mess').slideToggle("slow"); $('#arrow_mess').slideToggle("slow"); $('#arrow_not').hide(
$('#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();
});
您可以在中找到更多信息,为什么不使用jquery$.ajax函数呢?它更具交叉性且更方便。请在使用它的HTML的上下文中显示代码。如何在变量中保存上下文:document.body?您根本不必添加上下文选项。
$.ajax({
url: "test.html",
context: document.body
}).done(function() {
....
});