How synchronous methods work

I am wondering if anyone can help me understand some asynchronous javascript concepts ...

Let's say I make an asynchronous ajax call like this:

  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? As soon as I make the call to open (), the execution is done directly under the open (), and the other "thread" enters the asynch function after the ajax request is completed?

Or, does the browser wait for the request to complete, make an Asynch call, and then execution continues immediately after opening?

Thank!

+3
source share
2 answers

. / ?

+3

-, xmlhttp.send.

. , .

+1

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


All Articles