I have lots of different functions that send AJAX requests to save different parts of the page. When the user clicks save, All these functions are run like so.
function savePage() {
    if (!confirm('Save changes?')) return false;
    saveSortOrder();
    saveAllWidth();
    saveAllTinyMCE();
    saveAllWidgetRm();
    location.reload();  
}
Once everything is saved, I want to reload the page but location.reload() runs before everything is finished.
A typical save function looks like this but some are much bigger and there are lots of them
function saveAllPublic() {
    $('.widget').each( function(){
        var parentID = $(this).attr('id');
        var publicState = $(this).attr('data-public');
        $.post('widgets/manage_widgets.php', {
            update: 'publicity',
            wd_parent: parentID,
            public: publicState
        });
    });
}
Basically, I want all the POSTs to complete before reloading the page.
 
    