I'm trying to get a page to load faster by splitting all the database calls into separate scripts and running them at the same time with ajax. I did some research and found jQuery has a $.when().then() function that can take care of this. I am OK with the basics of ajax but the deferred/promise concept has me a little confused. I have tried the below code but it will only load the data from the first ajax result. Commenting out the first one will load the next one but only one will show on the page. Appreciate any help with this. Thanks.
$.when( $.post('extensions/ext_adjustments_investigation/general_details.php', {sku: sku},function(data) { result = data; }),
$.post('extensions/ext_adjustments_investigation/location_information.php', {sku: sku},function(data1) { result1 = data1; }),
$.post('extensions/ext_adjustments_investigation/annotations.php', {sku: sku},function(data2) { result2 = data2; }),
$.post('extensions/ext_adjustments_investigation/adjustment_history.php', {sku: sku},function(data3) { result3 = data3; })
).then(
function() {
$("#searching").addClass("hidden");
$("#load").prop("disabled",false);
$("#general").html(result).hide().slideDown()("slow");
$("#location").html(result1).hide().slideDown()("slow");
$("#anno").html(result2).hide().slideDown()("slow");
$("#history").html(result3).hide().slideDown()("slow");
}
);