點登入沒有反應
梁恒祥
梁恒祥 2018-06-03 09:58:11
0
4
1682

 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', '接受' => '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,如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', '連線' => '關閉', '主機' => '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',

'密碼|密碼'=>'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('名稱' ,$data['名稱'])

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

});

// 暫停($結果); //測試查詢結果

  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)
小皮

點登陸沒反映應該是前端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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!