<?php header("Content-type:text/html; charset=utf-8"); //登录一般都是post请求 所以我们这里使用一个变量接受所以post请求 $data = $_POST; //吧所有获取的参数赋值给data if(!$data){ ajaxResult(['status'=>-1,'msg'=>'请使用POST请求','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]); } function ajaxResult($data){ //这里定义一个方法用来返回 json请求 exit(json_encode($data)); }
参考 https://www.cnblogs.com/quan846951943/archive/2021/08/02/15089782.html
标签:username,ajaxResult,msg,Ajax,result,后台,POST,data From: https://www.cnblogs.com/wlei5206/p/17012534.html