2012-02-22 21 views
2

私はモバイルアプリです。私は、Ajaxは私がこれをどのように行うことができます完了後にjquery ajax呼び出しを実行する

...私は完全な機能がsqliteのに挿入されたすべてのデータの後に実行したい

   $.ajax({ 
        url: 'http://www.xxxxxxxxxxxxxxxx', 
        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], 
           //$.mobile.changePage('#page3', 'slide', false, true), 
           null); 
          });    
         }); 
        }, 
        complete: function(){test = 1;} 
       }); 

このコードウェブサーバの聖霊降臨祭からのデータを受信するために呼び出しを使用します?

completeコールバックがあなたのexecuteSql機能であるべき

+0

あなたのAJAX呼び出しからではなく、sqliteからイベントを取得する必要があります。 –

答えて

2

をアドバイスをしてください。 executeSqlは3つの引数を受け入れる必要があります。

var sqlString = 'INSERT into bill (barcode, buildingcode, buildingaddress, flatname, flatdescription, entryseason, period, amount, pastpayments, todaypayments, receiptno) VALUES (?,?,?,?,?,?,?,?,?,?,?);'; 
var sqlValues = [post.Id, post.Code, post.Address, post.Name, post.Description, post.EntrySeason, post.Period, post.Revenue, post.PastPayments, post.todaypayments, post.receiptno]; 
var callback = function(){ test = 1; } 
executeSql(sqlString, sqlValues, callback); 

あなたのexecuteSql機能を編集し、それが第三引数を受け入れ行い、callback();で機能を終了する必要があります。

もう1つの注意点として、このようなSQL問合せにセキュリティの問題はありませんか?大事なのは?

+0

コールバックを一度実行する方法はありますか?各sqliteのインサートで実行されるコールバック関数 – kosbou

+0

SQLは非同期に実行されるため、どのように表示されるのかわかりません。返されるコールバックの数をカウントし、返されたコールバックの数が送信された要求の数と等しい場合に関数を実行できます。 –

関連する問題