lundi 30 novembre 2015

Show Loading Screen while multiple AJAX calls with SQlite transactions haven't finished

I have got multiple AJAX calls with SQlite transactions to add data. For some reasons one of the AJAX calls not executing but hideLoadingScreen() fires fine.

I am using this code to count callbacks:

showLoadingScreen();

var callbackCount = 0;

function ajaxCallback() {
  ++callbackCount;
  if (callbackCount >= 3) {
  hideLoadingScreen();
  }
}

And three of my AJAX calls with SQlite transactions look like:

$.ajax({
    url: url,
    jsonp: "callback",
    dataType: "jsonp",
    success: function (data) {
        db.transaction(function (tx) {
            $.each(data.result, function (i, item) {
                tx.executeSql('INSERT OR REPLACE INTO db_table (id, type, title) VALUES (?,?,?)', [item.ID, "update", item.post_title]);
            });
            ajaxCallback();
        });
    }
});

How can I make count callbacks

Aucun commentaire:

Enregistrer un commentaire