2012-02-22 12 views
0

私はモバイルアプリです。私は、Ajaxは、このコードをウェブサーバからデータを受信するために呼び出して使用します。完了後にjquery ajaxコールを一度実行する

  $.ajax({ 
       url: 'http://www.xxxxxxxxxxxx', 
       data: {name: 'Chad'}, 
       dataType: 'jsonp', 
       success: function(data){ 
        $.each(data.posts, function(i,post){ 
         $.mobile.notesdb.transaction(function(t) { 
         t.executeSql('INSERT into bill (barcode, buildingcode, buildingaddress, flatname, flatdescription, entryseason, period, amount, pastpayments, todaypayments, receiptno) VALUES (?,?,?,?,?,?,?,?,?,?,?);', 
          [post.Id, post.Code, post.Address, post.Name, post.Description, post.EntrySeason, post.Period, post.Revenue, post.PastPayments, post.todaypayments, post.receiptno], 
          function(){ 
           bill = 1; 
           $('#mycontent').append("bill - OK"); 
          } 
         ); 
         });    
        }); 
       } 
      }); 

私はbill - OKはsqliteのに挿入されたすべてのデータの後に一度だけ表示します。

$.ajax({ 
    url: 'http://www.xxxxxxxxxxxx', 
    data: {name: 'Chad'}, 
    dataType: 'jsonp', 
    async: false, //this line here 
    //... 

EDITかについて

OK、::

$.each(data.posts, function(i,post){ 
    //rest of stuff 
}); 

$('#mycontent').append("bill - OK"); //this line outside the each() call 
+0

をそして、あなたの実際の問題が..です? –

+0

bill - sqliteへの挿入のたびにOKが表示されます... 20回 – kosbou

+0

'$ .each'ループの外にあなたの" bill - OK "行を移動します。 – SenorAmor

答えて

1

はこれを試してみてください。

+0

thx thatsは私のために働く – kosbou

0

は、追加しようと

success: function(data){ 

    var count = data.posts.length; 

    $.each(data.posts, function(i,post){ 
     $.mobile.notesdb.transaction(function(t) { 
      t.executeSql(<...>, 
       function() { 
        bill = 1; 
        if (--count == 0) { 
         $('#mycontent').append("bill - OK"); 
        }       
       } 
      ); 
     });    
    }); 
} 
+0

いいえ動作しません – kosbou

+0

このように請求は一度だけではなく挿入前に完了 – kosbou

+0

asynch:false line? – aletzo

関連する問題