点登录没有反应
梁恒祥
梁恒祥 2018-06-03 09:58:11
[PHP讨论组]

 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');

}


梁恒祥
梁恒祥

全部回复(1)
PHP中文网

点登陆没反映应该是前端AJAX 写的有问题 打开浏览器控制 台 检查 JS的错误

  • 回复 <script type="text/javascript"> $(function(){ $('#submit').on('click',function(){ //用ajax提交用户信息 $.ajax({ type: 'post', url: "{:url('loginCheck')}", data: $('#login').serialize(), dataType: 'json', success: function(data){ alert(data); switch (data.status) { case 1: //登录成功跳到首页 alert(data.message); window.location.href = "{:url('index/index')}"; break; case 0: //失败或验证不通过返回登录页 case -1: alert(data.message); window.location.back(); break; } } }) }) })
    梁恒祥 作者 2018-06-07 15:30:22
  • 回复 应该是用MySQL-Font创建的数据表,默认的id字段,首字母I大写,变成了Id,所以在Model\user中找不到id这个字段造成的。
    李桃子 作者 2018-11-07 22:11:51
  • 回复 我也是,但我检查了前台控制器,没报错啊
    新新新新生 作者 2019-01-02 15:31:55
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号