• 对于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

  • 相关阅读:
    AC自动机
    HDU
    2020牛客寒假算法基础集训营3 B 牛牛的DRB迷宫II
    POJ 3784 Running Median【维护动态中位数】
    CodeForces
    HDU 2444 The Accomodation of Students【二分图最大匹配问题】
    POJ 1201 Intervals【差分约束】
    POJ 2976 Dropping tests【0/1分数规划模板】
    2019牛客暑期多校训练营(第七场)A.String【最小表示法】
    POJ 1287 Networking【kruskal模板题】
  • 原文地址:https://www.cnblogs.com/acafaxy/p/2171049.html
Copyright © 2020-2023  润新知