2011-10-27 41 views
0

如何顯示我的代碼的Ajax響應?當我用async=true顯示的yy值只是最後一個值;我需要顯示從0a的所有值。它適用於async=false。這裏是我的代碼:Ajax響應沒有顯示在成功函數內

for(var jj=0;jj<a;jj++){ 
       var yy=jj; 
       var ins=12 
       var rou=13 
       /* */ 
       $.ajax({ 
          type:"GET", 
          url:"Select.php", 
          async:false, 
          data:"rou="+rou+ 
           "&ins="+ins, 

          success : function(t){ 

          $("#truk"+yy).text(t); 
          // Response not shown here 


          } //success 
       });    

       }  
+0

同步Ajax請求的循環?這真的會凍結瀏覽器,你應該考慮另一種方式。 – Marc

+0

因爲我需要所有的jj值,它試着同步 – venkat

+0

我不知道你的Select.php究竟做了什麼,但是簡單地修改Select.php來返回一個字符串數組並將for-loop在成功功能? – Naning

回答

0

但無論如何,它是Ajax調用的是你正在尋找的結果:

var syncResult = $.ajax('/echo/json/', { 
    async: false 
}); 
document.write(syncResult.responseText); 

看到它住在這裏:http://jsfiddle.net/alligator/6MsuZ/