javascript - How to use jquery when on post with success callback -


i have app needs 3 different post requests sync data, want 1 thing happen when 3 completed jquery when not working. posts use success function process data server sent back. here code:

var picuploads = $.post("http://www.epcmapp.co.za/php2/uploadpic.php", {images: jsonpics}, function (res) {     alert("ajax images return");         if(res != "" && res != "53554343455353")         alert(res); });  var pdfuploads = $.post("http://www.epcmapp.co.za/php2/uploadpdf.php", {pdfs: jsonpdf}, function (res) {     alert("ajax pdf return");             if(res != "" && res != "53554343455353")         alert(res); });  var sync = $.post("http://www.epcmapp.co.za/php2/sync.php", {data: json}, function (res) {     alert("ajax return");         var result = json.parse(res);         dropsynctables();     checkdb();     (var in result) {         populatedb(result[i].tostring());     }     readdb();          loadprojects();     loadadditional();     loadprocessrows();     loadattachments();                                 });  $.when(picuploads, pdfuploads, sync).then(function() {     $("#loadicn").attr("src", "images/check3.png"); }); 

the alerts in posts not pop , code inside jquery never runs. how supposed then?

first check console.log. find issue there. if find want kind of errorhandling , possible deffered objects:

$.when(picuploads, pdfuploads, sync)     .then(function() {         $("#loadicn").attr("src", "images/check3.png");     })     .fail(function(ts) {         alert('something failed');         console.log(ts.responsetext); //check in console went wrong here     }) 

it possible use done() , fail() $.post (as of jquery 1.5)

var picuploads = $.post("http://www.epcmapp.co.za/php2/uploadpic.php", {images: jsonpics}, function (res) {     alert("ajax images return");         if(res != "" && res != "53554343455353")         alert(res); }) .done(function() {   alert( "second success" ); }) .fail(function() {   alert( "error" ); }); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -