2011-04-06 54 views
0
function myfunction() { 
    ... 
    $(myarray).each(function() { 
     ... 
     $.ajax({ 
      ..., 
      async: false, 
      error: function() { 
       // I want to return false and quit from this function here 
       // no luck with return false, still continuing to the next loop 
      } 
     }); 
    }; 
} 

回答

2

使用一個變量:

function myfunction() { 
    var gotError=false; 
    $(myarray).each(function() { 
     if(gotError) return; 
     $.ajax({ 
      ..., 
      async: false, 
      error: function() { 
       gotError=true; 
      } 
     }); 
    }; 
    return !gotError; 
} 
+0

謝謝,將被標記爲9分鐘的答案。 – 2011-04-06 06:02:12