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属性

  • 相关阅读:
    python运行出现TypeError: super() takes at least 1 argument (0 given)错误
    史上最全Python数据分析学习路径图
    Windows平台Python编程必会模块之pywin32
    PyMySQL的基本使用
    python:让源码更安全之将py编译成so
    最高分是多少
    哪些技术可以用在WEB开发中实现会话跟踪
    自定义输入模板
    JAVA中HashMap和Hashtable区别
    Java中ArrayList与LinkedList的区别
  • 原文地址:https://www.cnblogs.com/limingluzhu/p/2293951.html
Copyright © 2011-2022 走看看