zoukankan      html  css  js  c++  java
  • 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属性

  • 相关阅读:
    php上传进度条
    array_combine — 创建一个数组,用一个数组的值作为其键名,另一个数组的值作为其值
    password_hash 与 password_verify
    这是一个微信带参数的二维码,自定义菜单,与图文回复
    go to 语句用起来还是挺方便的
    初次使用海豚php的一个例子
    图片下载
    一对一的关联映射
    延迟加载
    proxy和proxy-no的策略取值区别
  • 原文地址:https://www.cnblogs.com/limingluzhu/p/2293951.html
Copyright © 2011-2022 走看看