zoukankan      html  css  js  c++  java
  • 对于jQuery中$.ajax方法的新认识

    使用jQuery做web前端开发的人,相信对$.ajax这个方法不会陌生,我也一直在使用,可是一直没有深究过其中每个参数的含义,比如今天要说到的 async 参数。

    这个参数官方手册上给出的解释是:
    async Boolean
    Default: true
    By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.

    在这里,async默认的设置值为true,这种情况为异步方式,就是说当ajax发送请求后,在等待server端返回的这个过程中,前台会继续 执行ajax块后面的脚本,直到server端返回正确的结果才会去执行success,也就是说这时候执行的是两个线程,ajax块发出请求后一个线程 和ajax块后面的脚本。而当async为false时则脚本会等带server的响应,在server返回结果之后才会执行后面的脚本,在数据返回之前等于javascript脚本是挂起的。

    这个其实不难理解,不过如果和$(document).ajaxStart()以及$(document).ajaxStop()结合起来使用,两者的差别就大了,async为true时默认会触发$(document).ajaxStart()和$(document).ajaxStop(),也就是说当ajax请求为异步请求时,我们绑定在元素上的ajaxStart和ajaxStop才会起效果,反之,当async为false即ajax为同步请求时,这两个方法以及相关的ajaxComplete等都会失效。

    转:http://hmw.iteye.com/blog/1161724

  • 相关阅读:
    Codeforces Round #642 (Div. 3)
    [P4980] 【模板】Polya定理
    [SCOI2016] 幸运数字
    [P4389] 付公主的背包
    [CF438E] The Child and Binary Tree
    最长异或路径
    [AHOI2013] 作业
    [P4841] [集训队作业2013] 城市规划
    Python 第三方库国内镜像安装
    [CF1202D] Print a 1337-string...
  • 原文地址:https://www.cnblogs.com/acafaxy/p/2171049.html
Copyright © 2011-2022 走看看