No response when clicking login
梁恒祥
梁恒祥 2018-06-03 09:58:11
0
4
1756

 LANG ] E:\phpStudy\PHPTutorial\WWW\hycy\thinkphp\lang\zh-cn.php

[ ROUTE ] array ( )

[ HEADER ] array ( 'cookie' => 'thinkphp_show_page_trace=1|2', 'accept-language' => 'zh-CN,zh;q=0.8', 'accept-encoding' => 'gzip, deflate', 'referer' => 'http://a.com/index.php/index/user/login', 'accept' => 'text/html,application/xhtml xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'content-type' => 'application/x-www-form-urlencoded', 'user-agent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.3.2.17331', 'upgrade-insecure-requests' => '1', 'origin' => 'http://a.com', 'cache-control' => 'max-age=0', 'content-length' => '23', 'connection' => 'close', 'host' => 'a.com', )

[ PARAM ] array ( 'name' => 'jh', 'password' => '123456', )

[ VIEW ] E:\phpStudy\PHPTutorial\WWW\hycy\application\index\view\user\login.html [ array ( 0 => 'title', ) ]

if(Request::isAjax()){

//数据验证

$data = Request::post();//获取ajax提交数据

$rule = ['name|姓名'=> 'require|length:2,20|chsAlphaNum',

'password|密码'=>'require|alphaNum',];

$res=$this->validate($data,$rule);

if (true !== $res){  //验证失败

  return ['status'=> -1, 'message'=>$res];

  }else { //验证成功

  //2. 查询数据表zh_user中,并对结果进行判断

  $result = Syuser::get(function($query) use ($data){

  $query->where('name',$data['name'])

   ->where('password',sha1($data['password']));

  });

  // halt($result); //测试查询结果

  if(null == $result){

  return ['status'=>0, 'message'=>'邮箱或密码不正确,请检查~~'];

} else{

//将用户ID写入session中

Session::set('user_id', $result->id);

Session::set('user_name', $result->name);

Session::set('is_admin', $result->is_admin);

return ['status'=>1, 'message'=>'恭喜,登录成功~~'];

}

}  

}else{

$this->error('请求类型错误','login');

}


梁恒祥
梁恒祥

reply all(1)
小皮

If there is no response when clicking login, there should be a problem with the front-end AJAX writing. Open the browser console and check for JS errors.

  • reply <script type="text/javascript"> $(function(){ $('#submit').on('click',function(){ //Submit user information using ajax $.ajax({ type: 'post', url: "{:url('loginCheck')}", data: $('#login').serialize(), dataType: 'json', success: function(data){ alert(data); switch(data.status) { case 1: //Log in successfully and jump to the homepage alert(data.message); window.location.href = "{:url('index/index')}"; break; case 0: //Failure or verification fails and returns to the login page case-1: alert(data.message); window.location.back(); break; } } }) }) })
    梁恒祥 author 2018-06-07 15:30:22
  • reply It should be caused by the data table created with MySQL-Font. The default id field, with the first letter I capitalized, has become Id, so the id field cannot be found in Model\user.
    李桃子 author 2018-11-07 22:11:51
  • reply Me too, but I checked the front controller and there was no error.
    新新新新生 author 2019-01-02 15:31:55
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template