jq-ajax-get

2023-05-13,

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";
} ?>

jq-ajax-get的相关教程结束。

《jq-ajax-get.doc》

下载本文的Word格式文档,以方便收藏与打印。