0

I have this call :

// some code;
myAjaxCall(
      function abcd() {};
);

// more code

Can the more code and abcd executing in the same thread or different thread. I know it is asynchronous.

javaguy
  • 4,404
  • 10
  • 32
  • 35

2 Answers2

3

Assuming myAjaxCall is an ajax wrapper, and the first argument is the complete callback, the answer is "more code" will run before abcd function. But I'd need to see myAjaxCall function to know what is really going on.

Remember, the complete callback happens when ajax retruns. "more code" executes in the normal execution path.

Josiah Ruddell
  • 29,697
  • 8
  • 65
  • 67
2

The AJAX request is asynchronous, but the Javascript code is synchronous and single threaded.

The code following the AJAX call will complete before the abcd function can run. The event that occurs when the response arrives can't be handled until the code exits and returns control to the browser.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005