2011-06-10 125 views
1

大家好我從來沒有過,我無法和谷歌解決的一個問題... 所以這是代碼:jQuery的AJAX調用不會停止重複一遍又一遍

function loadData(url, type){ 
     loading_show(); 
     var quality = getCheckedRadio(); 
     $.ajax 
     ({ 
      type: "POST", 
      url: "http://.../core.php", 
      data: "url="+url +"&quality="+quality +"&type="+type, 
      success: function (msg) 
      { 
       $("#url").ajaxComplete(function(event, request, settings) 
       { 
        //loading_hide(); 
        //$("input[type=button]").removeAttr("disabled");   
        $("#url").html(msg); 
        window.onload=$("#url").fadeIn('slow'); 
       }); 
      } 
     }); 
     return false; 
} 
function getmp3(id){ 
     var quality = getCheckedRadio(); 
     $.ajax 
      ({ 
       type: "POST", 
       url: "http://.../core.php", 
       data: "id="+id +"&quality="+quality, 
       success: function (msgs) 
       { 
        $("#dload").ajaxComplete(function(event, request, settings) 
        { 
         loading_hide(); 
         $("input[type=button]").removeAttr("disabled");   
         $("#dload").html(msgs); 
         window.onload=$("#dload").fadeIn('slow'); 
        }); 
       } 
      }); 
} 

所以,第一個函數工作得很好,core.php返回一些html數據和一個javascript:「getmp3('bla');」因此它觸發了第二個函數。問題在於,'getmp3'函數中的$ .ajax一遍又一遍地重複,它溢出瀏覽器。它做到了,但它只是一遍又一遍地停止呼叫。

回答

0

你不需要ajaxComplete函數,你可以把代碼直接放在成功函數中。

function loadData(url, type){ 
     loading_show(); 
     var quality = getCheckedRadio(); 
     $.ajax 
     ({ 
      type: "POST", 
      url: "http://.../core.php", 
      data: "url="+url +"&quality="+quality +"&type="+type, 
      success: function (msg) 
      { 
        //loading_hide(); 
        //$("input[type=button]").removeAttr("disabled");   
        $("#url").html(msg).fadeIn('slow'); 
      } 
     }); 
     return false; 
} 
function getmp3(id){ 
     var quality = getCheckedRadio(); 
     $.ajax 
      ({ 
       type: "POST", 
       url: "http://.../core.php", 
       data: "id="+id +"&quality="+quality, 
       success: function (msgs) 
       { 
         loading_hide(); 
         $("input[type=button]").removeAttr("disabled");   
         $("#dload").html(msgs).fadeIn('slow'); 
       } 
      }); 
} 
+0

非常感謝很多人,這解決了我的問題:) – Nikouay 2011-06-10 10:23:52

相關問題