zoukankan      html  css  js  c++  java
  • JS中Ajax的同步和异步

    ajax同步 : 意味着此时请求Server后,JS代码不再继续执行,等待Server返回后才继续往下执行。

    ajax异步 : 意味着此时请求Server后,JS代码继续执行,不管Server什么时候返回。

    var f;
    $.ajax({
          type : "post",
          url : "cuoche/checkCuocheInfoExpireTime.do",
          async:false,  //使用同步的方式,true为异步方式
          data : {
            "carId" : carId
          },
          dataType : "json",
          success : function(data) {
            console.info(data);
            if(typeof(data.flag) == 'undefined' || data.flag == '' || data.flag == null){
              f =  false;
              return ;
            }else{
              f = true;
              return ;
            }
          } ,
          error : function(data) {
            f = false;
            return ;
          }
        });
    var f;
    $.ajax({
          type : "post",
          url : "cuoche/checkCuocheInfoExpireTime.do",
          async:true,  //使用异步的方式,true为异步方式
          data : {
            "carId" : carId
          },
          dataType : "json",
          success : function(data) {
            console.info(data);
            if(typeof(data.flag) == 'undefined' || data.flag == '' || data.flag == null){
              f =  false;
              return ;
            }else{
              f = true;
              return ;
            }
          } ,
          error : function(data) {
            f = false;
            return ;
          }
        });
  • 相关阅读:
    BCP 命令
    模板复习【updating】
    bzoj3716/4251 [PA2014]Muzeum
    bzoj4318 OSU!
    uoj308 【UNR #2】UOJ拯救计划
    bzoj4695 最假女选手
    省队集训 Day7 选点游戏
    hdu5828 Rikka with Sequence
    bzoj2482 [Spoj1557] Can you answer these queries II
    省队集训 Day6 序列
  • 原文地址:https://www.cnblogs.com/smileblogs/p/9564215.html
Copyright © 2011-2022 走看看