Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  40] [ 5]  / answers: 1 / hits: 31289  / 12 Years ago, sun, may 13, 2012, 12:00:00

PHP returns value with 1-2 second delay jQuery.post doesn't wait for response.



How do you think, is it possible to fix that problem and wait for response?



    $.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 );


Note the same function with get works well



    $.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)
} );

More From » jquery

 Answers
76

$.post is asynchronous, you need to use $.ajax and set async to false, that way you will be able to wait for the response.
You can read more about it here: http://api.jquery.com/jQuery.ajax/


[#85610] Friday, May 11, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yulisa

Total Points: 436
Total Questions: 102
Total Answers: 123

Location: Palau
Member since Tue, May 30, 2023
1 Year ago
;