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 ;
          }
        });
  • 相关阅读:
    Iview多行表单增删、表单校验
    Linux常用命令+Git命令
    前端架构师图谱
    第八章学习心得
    第七章学习心得
    第6章学习心得
    第5章学习总结
    第四章心得体会
    第三章学习心得
    第二章学习心得
  • 原文地址:https://www.cnblogs.com/smileblogs/p/9564215.html
Copyright © 2011-2022 走看看