• jq-ajax-get


    get有三个参数,第一个时候url,第二个是数据,第三个是回调函数(可以用返回值表示,如下所示)

    执行正确时,返回的依次是res,type,xhr。

    执行错误连接不上的的依次是xhr,type,res.

    $("#btn").click(function(){
            var url = "http://localhost/1908/jq-ajax/data/data.php"
            var xhr = $.get(url,{
                user:$("#user").val(),
                pass:$("#pass").val()
            })
    
             xhr.success(function(res,type,xhr){
                 console.log(res)
             })
    
             xhr.error(function(xhr,type,res){  //未连接上
                 console.log(xhr)   //对象
                 console.log(type)  //error
                 console.log(res)   //Not Found
             })
        ==========================================
          xhr.then(function(res,type,xhr){   //也可通过类似pormise,正确连接执行第一个函数,错误执行第二个函数
          console.log(res,type,xhr) res:成功的返回值 type:连接是否成功 xhr:对象 ; 账号密码正确输出1; type为success; xhr:输出对象
          },function(xhr,type,res){
          console.log(xhr,type,res) //连接失败返回的是错误信息
          })
     

     php代码:

    <?php
    
        $u = @$_REQUEST["user"];
        $p = @$_REQUEST["pass"];
    
        $user = "admin";
        $pass = 123456;
    
        if($u == $user && $p == $pass){
            echo "1";
        }else{
            echo "0";
        }
    
    ?>
  • 相关阅读:
    线程安全问题
    Apache DBUtils框架 结果处理器
    编写JDBC框架:(策略设计模式)
    Java编写准备数据源
    理解事务的4种隔离级别
    JavaBeans与内省(Introspector)
    getRequestURI,getRequestURL的区别
    JDBC学习笔记——PreparedStatement的使用
    JDBC的编码步骤
    MySQL 完整性约束
  • 原文地址:https://www.cnblogs.com/hy96/p/11558970.html
Copyright © 2020-2023  润新知