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

  • 相关阅读:
    Javascript中 this的精要总结
    优秀布局的链接
    前端测试框架(学习之路)前言
    SQL之Linq学习篇(目录)
    WebApi 研习之路 (目录)
    关于带参数模糊查询的方法 like --转载自 寂寞沙洲(博客园)
    .Net 程序在自定义位置查找托管/非托管 dll 的几种方法
    .net 生成非托管代码
    GridControl单元格编辑验证的方法
    扩展方法实现DevExpress控件校验
  • 原文地址:https://www.cnblogs.com/limingluzhu/p/2293951.html
Copyright © 2011-2022 走看看