我在移动应用中。我使用ajax调用从webserver接收此代码的数据
$.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;}
});
我希望在所有数据插入sqlite后执行完整的功能...
我该怎么办?
请咨询
答案 0 :(得分:2)
complete
回调应该在您的executeSql
功能中。 executeSql
应该接受三个论点:
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();
结束函数。
另一方面,是不是像这样传递SQL查询是一个安全问题?比如,一个主要的?