<?php header("Content-type:text/html; charset=utf-8"); //登录一般都是get请求 所以我们这里使用一个变量接受所以get请求 $data = $_GET; //吧所有获取的参数赋值给data if(!$data){ ajaxResult(['status'=>-1,'msg'=>'请使用GET请求','result'=>[]]); } if(!isset($data['password']) || !isset($data['username'])){ //判断所需要的参数是否存在 ajaxResult(['status'=>-1,'msg'=>'缺少参数','result'=>[]]); } if($data['username'] == 'admin' && $data['password'] == '123456'){ //判断账号密码是否存在 $r = ['username'=>'admin','password'=>'123456']; //需要返回的数据 ajaxResult(['status'=>1,'msg'=>'登录成功','result'=>$r]); }else{ ajaxResult(['status'=>-100,'msg'=>'账号或密码错误','result'=>[]]); } function ajaxResult($data){ //这里定义一个方法用来返回 json请求 exit(json_encode($data)); }
参考 https://www.cnblogs.com/quan846951943/archive/2021/08/02/15089782.html
标签:status,ajaxResult,GET,msg,Ajax,result,后台,data From: https://www.cnblogs.com/wlei5206/p/17012529.html