【发布时间】:2011-09-30 08:13:27
【问题描述】:
我有以下代码,它获取一个 json 记录集并在客户端 Web Sql 存储的三个不同表中插入一些数据。
如何拦截 databaseSync() 函数的结束? 我想要做的是显示警报或更好的 ajax spinner gif,以便在同步完成时通知用户。
非常感谢您的帮助, 哎哟!
function databaseSync() {
// table one
$.getJSON("http://192.168.1.40:8888/iOS/mobilesrv/index.php?ACT=one", function(json) {
$.each(json.results, function(i, res) {
db.transaction(function(tx) {
tx.executeSql("INSERT INTO table1 (A, B, C, D) VALUES (?,?,?,?) ", [res.A, res.B, res.C, res.D], onSuccess, onError);
});
});
});
// table two
$.getJSON("http://192.168.1.40:8888/iOS/mobilesrv/index.php?ACT=two", function(json) {
$.each(json.results, function(i, res) {
db.transaction(function(tx) {
tx.executeSql("INSERT INTO table1 (A, B, C, D) VALUES (?,?,?,?) ", [res.A, res.B, res.C, res.D], onSuccess, onError);
});
});
});
// table three
$.getJSON("http://192.168.1.40:8888/iOS/mobilesrv/index.php?ACT=three", function(json) {
$.each(json.results, function(i, res) {
db.transaction(function(tx) {
tx.executeSql("INSERT INTO table1 (A, B, C, D) VALUES (?,?,?,?) ", [res.A, res.B, res.C, res.D], onSuccess, onError);
});
});
});
}
【问题讨论】:
-
+1 您需要等到所有
onSuccess或onError都已被调用。 +1 对于任何有很好的写作方式的人。
标签: jquery database html web-sql