<!--Ajax submission script-->
$(function(){
//Add a click event to the login button
$("#login").on('click ',function (event) {
$.ajax({
type:"POST", //The submission method is POST
url:"{:url('checkLogin')}", //Settings The address of the script file for submitting data processing
data:$("form").serialize(), //Serialize the data of the current form before submitting it
dataType:'json', //Set the submission data The type of JSON
SUCCESS: Function (data) {// Only when the return signs are 1 before processing
if (data.status == 1) {// Only when the return status value is 1, the jump is allowed to jump Go to the background
alert(data.message); //First pop up a prompt box to prompt the user for success
use using ’ ’ s ’ to use - Else {// Output error information
Alert (data.message);
}
}
});
})
## user.php
<?php
namespace app\index\controller;
use app\index\controller\Base;
//use think\Controller;
use think\Request;
use app\index\model\User as UserModel;
use think\db;
class User extends Base
{
//Login page
public function login()
{
//return $this->view-> fetch();
return $this->view-> fetch();
//return view();
}
//Verify login $this->>validate($data,$rule,$msq) The data that needs to be verified, the rules for verifying data, and the prompt message after verification fails
public function checkLogin(Request $request)
{
//Initial return parameters
$status =0;
$result ='';
$data = $request -> param();
use using using using >'require', //The password is required
Prompt message
$msg=[
'name'=>['require'=>'The username cannot be empty, please check'],
'password'=>['require' =>'The password cannot be empty, please check'],
'verify'=>[
' =>'Verification code error',
],
];
String, it is a user-defined error prompt
$result=$this->validate($data,$rule,$msg);
//Execute if the verification is passed
if ($ Result === TRUE) {
// Construction query condition
$ map = [
'name' = & gt; $ data ['name'],
'password ' => md5($data['password'])
];
//Query user information
$user=UserModel::get($map);
if( $user == null){
$result = 'The user was not found';
}else{
$status = 1;
$result = 'Verification passed, click [OK] to enter'; # }
return ['status'=>$status,'message'=>$result,'data'=>$data];
}
//Log out
public function logout(){
}
}
After entering the correct account password verification code, the page becomes unresponsive and the error is this
No, the original poster
Sir, I also encountered the same problem and reported an error of 500. How did I solve it?
This is poisonous. Think about it, it has nothing to do with this request; however, if you modify the third parameter and delete it or delete the customized error message, you can connect again. What is going on! ?
。。。