zoukankan      html  css  js  c++  java
  • 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";
        }
    
    ?>
  • 相关阅读:
    ToString格式化
    [转]vc中socket编程步骤
    [XAML学习资料] 验证用户提供的数据ValidationRule
    VS2008下安装boost
    [ASP.NET用户验证一]Forms验证
    VISTA IIS Worker Process 已停止工作 解决办法
    [MFC入门二]四种不同对象
    删除TFS项目
    [WPF学习资料] WPF简介
    IIS7下配置PHP5
  • 原文地址:https://www.cnblogs.com/hy96/p/11558970.html
Copyright © 2011-2022 走看看