0
点赞
收藏
分享

微信扫一扫

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,正确连接执行第一个函数,错误执行第二个函数
账号密码正确输出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";
}

?>

 

长风破浪会有时,直挂云帆济沧海



举报

相关推荐

0 条评论