• JQuery ajax回调函数


    转自http://zhengyh2008.blog.163.com/blog/static/13894713201003041633526/

    jquery ajax 回调函数 返回值  

    js文件:

    $.ajaxSetup({
      async: false
      });

    function oncheck(oid){
        var rs=true;
            
        if(oid=="stunum") {                
            $.post("util.php",checkString(oid),function(data){
          if(decodeURI(data).trim()== 'used'){
                
                alert("该学号已换注册!");
               
                 rs=false; 
                }
               
            });
        }
      
       return rs;
    }
    function onSub(){

        return oncheck("stunum");

        
    }

    注意: 函数oncheck(oid){的写法,写法2.的返回值可能永远是true;

    写法1:function oncheck(oid){
        var rs=true;
            
        if(oid=="stunum") {                
            $.post("util.php",checkString(oid),function(data){
          if(decodeURI(data).trim()== 'used'){
                
                alert("该学号已换注册!");
               
                 rs=false; 
                }
               
            });
        }
      
       return rs;
    }
    写法2 写法1:function oncheck(oid){
       
            
        if(oid=="stunum") {                
            $.post("util.php",checkString(oid),function(data){
          if(decodeURI(data).trim()== 'used'){
                
                alert("该学号已换注册!"); 
                
                 retrun false; 
                }
               
            });
        }
      
       return true;
    }

    Ajax请求默认的都是异步的
    如果想同步 async设置为false就可以(默认是true)

    var html = $.ajax({
      url: "some.php",
      async: false
    }).responseText;

    或者在全局设置Ajax属性

  • 相关阅读:
    MySQL++:(转)mybatis 常用 jdbcType数据类型
    CF1556F Sports Betting (状压枚举子集DP)
    ICPC Greater New York Region 2020 F
    post方式实现导出/下载文件
    自定义一个v-if
    在vue项目中引用element-ui时 让el-input 获取焦点的方法
    element-select当下拉框数据过多使用懒加载
    vue强制刷新组件更新数据的方式
    .net core efcore dbfirst(sqlserver,mysql,oracle,postgresql)
    camunda安装配置mysql以及整合springboot
  • 原文地址:https://www.cnblogs.com/limingluzhu/p/2293951.html
Copyright © 2020-2023  润新知