2011-06-10 67 views
0

在生成內容之前,我正在爲div添加加載gif圖像。它在Firefox中工作正常,但在Internet Explorer中不起作用。下面是我的代碼beforeSend在jQuery中使用ajax時不能在Internet Explorer中工作

感謝堆

<script type="text/javascript"> 
j(document).ready(function() { 

    j('#sliderform').submit(function() { 
    //j('#dash1').html('loading....'); 

    bodyContent = j.ajax({ 

     beforeSend: function(){ 
      $("#dash1").append('abhinab...'); 
      //alert("loading,.."); 
      j('#dash').html('loading....'); 
      j('#dash').html('<img src="../resources/images/loading.gif" >'); 
    //document.getElementById('loading').innerHTML = '<img src="../resources/images/loading.gif" >'; 
     // document.getElementById('dash').innerHTML = '<img src="../resources/images/loading.gif" >';   
      }, 

      url: "dashboardreload.php", 
      global: true, 
      type: "POST", 
      data: ({min : j("#min").val(),max : j("#max").val()}), 
      dataType: "html", 
      async:false, 
      success: function(msg){ 
      // drawChart(); 

      } 
     } 
    ).responseText; 
    //j('#dialog-form').html(''); 
    //j("#dialog-form").dialog("close"); 
    //document.getElementById('dash').innerHTML = '<img src="../resources/images/loading.gif" >'; 
    j('#dash').html(bodyContent); 

    drawChart(); 

    //confirm(bodyContent); 
    return false; 
    }); 
}); 
</script> 
+0

如果您使用的是jQuery 1.4,那麼http://stackoverflow.com/questions/5817238/jquery-ajaxsetup-beforesend-not-executing-in-ie8可能是有趣的。 – GordonM 2011-06-10 11:57:53

回答

0

嘗試增加 「VAR」 每一個變量之前:

var bodyContent = j.ajax({.... 
0

好吧,讓我們來看看。 @ ArtoAle的回覆很好:不要使用全局變量。

真實需要注意的是,您正在對ajax進行同步調用(async屬性爲false)。這將阻塞JavaScript線程運行的UI線程,直到數據返回後恢復。也許在IE中,當UI線程被阻塞時,DOM的變化不會被渲染,但是它們在Firefox中執行?不知道,但我肯定會讓這個調用成爲一個異步調用。

如果這樣做,beforeSend適用於我在這裏以你描述的方式與IE8和jQuery 1.6.1。

相關問題