How do ansynchronous methods work

Posted by Polaris878 on Stack Overflow See other posts from Stack Overflow or by Polaris878
Published on 2010-03-31T22:35:44Z Indexed on 2010/03/31 23:43 UTC
Read the original article Hit count: 361

Filed under:
|
|

Hello, I'm wondering if anyone can help me understand some asynchronous javascript concepts...

Say I make an asynch ajax call like so:

  xmlhttp=new XMLHttpRequest();
  xmlhttp.onreadystatechange= myFoo;
  xmlhttp.open("GET",url,true);

Here is my callback function:

function myFoo()
{
if (xmlhttp.readyState==4)
  {
  if (xmlhttp.status==200)
    {
    // Success message
    }
  else
    {
    // some error message
    }
  }
}

Now, where and when does the execution path start again? Once I make the call to open(), does execution continue directly below the open() and another "thread" enters the asynch function once the ajax request has been completed?

Or, does the browser wait for the request to complete, make the Asynch call, and then execution continues right after the open?

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about asynchronous