2013-09-29 33 views
0
$('#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和爲了工作重新OPER鉻,在FirefoxAjax錯誤只有第一個請求發送

+1

你爲什麼不使用jquery阿賈克斯$功能的更多信息AJAX功能?這是crossbrowser和更方便。 – kasitan

+0

請在您使用HTML的上下文中顯示您的代碼。 – Quentin

回答

2

你已經在使用工作正常jQuery的,爲什麼不試試它像下面

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

您可以找到manual

+0

如何保存上下文:document.body in a var? –

+0

您不一定必須添加上下文選項。 –