如何ansynchronous方法工作 [英] How do ansynchronous methods work

查看:135
本文介绍了如何ansynchronous方法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有人能帮助我理解一些异步JavaScript概念...

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

说我做了以下这样一个异步调用Ajax:

Say I make an asynch ajax call like so:

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

下面是我的回调函数:

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

现在, 哪里以及何时执行路径重新开始?一旦我打这个电话开(),不执行继续正下方的open()和另一种线程进入异步函数一次Ajax请求已经完成?

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?

谢谢!

推荐答案

下面是pretty的很好的解释。 <一href="http://stackoverflow.com/questions/598436/does-an-asynchronous-call-always-create-call-a-new-thread/617119#617119">http://stackoverflow.com/questions/598436/does-an-asynchronous-call-always-create-call-a-new-thread/617119#617119

Here is a pretty good explanation. http://stackoverflow.com/questions/598436/does-an-asynchronous-call-always-create-call-a-new-thread/617119#617119

这篇关于如何ansynchronous方法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆