How to wait for an answer in $ .post jQuery

PHP returns a value with a delay of 1-2 seconds jQuery.post does not wait for a response.

Do you think it possible to fix this problem and wait for an answer?

$.post( sSource, aoData, function (data) { oCache.lastJson = jQuery.extend(true, {}, data); if ( oCache.iCacheLower != oCache.iDisplayStart ) { data.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower ); } data.aaData.splice( oCache.iDisplayLength, data.aaData.length ); abc(oCache); fnCallback(data); },"json" ); 

Pay attention to the same function as get works

  $.getJSON( sSource, aoData, function (json) { /* Callback processing */ oCache.lastJson = jQuery.extend(true, {}, json); if ( oCache.iCacheLower != oCache.iDisplayStart ) { json.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower ); } json.aaData.splice( oCache.iDisplayLength, json.aaData.length ); fnCallback(json) } ); 
+6
source share
1 answer

$. post is asynchronous, you need to use $ .ajax and set async to false, so you can wait for an answer. You can read more about this here: http://api.jquery.com/jQuery.ajax/

+16
source

Source: https://habr.com/ru/post/915618/


All Articles