Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop javascript execution till jquery JSON response

I am calling a third party webservice using getJSON callback. The function does not have a success handler attached to the function and since it is third party, I cannot edit the code also. By the time I receive the response, some of the javascript function in the page already executes.

Is there any way I can delay the execution of the Javascript function till I receive the response data from web service except setTimeout method.

like image 862
Shyama Avatar asked Aug 09 '26 02:08

Shyama


2 Answers

Description

You can use jQuery's .ajaxStart() and .ajaxComplete() events to get noticed if your ajax call is running. You can create a bool variable, something like isAjaxRunning and put this around the other javascript. So if isAjaxRunning is true, dont execute other javascript.

More Information

  • jQuery.ajaxStart()
  • jQuery.ajaxComplete()
like image 155
dknaack Avatar answered Aug 11 '26 14:08

dknaack


if you have access to the code you can make it synchonize by adding the attribute

async : false - then it won't be a asynchronous call like the normal ajax .

If you can post the sample code - that will give a clear picture.

like image 33
Vins Avatar answered Aug 11 '26 14:08

Vins