Below is a script that does not work in the order I want:
var masterData = {}; var tableNames = ['table1','table2','table3','table4','table5','table6']; var pullSqlData = function(){ tableNames.forEach(function(value) { if(storage.isEmpty(value)) { $.getJSON('http://domain.com?r=appsync/read&id='+value+ "&callback=", function(data){ masterData[value] = data; storage.set(value,data); }); } else { masterData[value] = storage.get(value); } }); }; $.when(pullSqlData()).done(function(){ console.log('all done'); });
After searching, I know that I can work higher if I manually do something like
$.when( $.getJSON('http://domain.com?r=appsync/read&id=table1&callback=', function(data){ masterData[value] = data; storage.set(value,data); }), $.getJSON('http://domain.com?r=appsync/read&id=table2&callback=', function(data){ masterData[value] = data; storage.set(value,data); }),
However, I was wondering if there is a way to make the right path higher.
* storage is an HTML5 localStorage jQuery plugin
source share