主頁 > 知識庫 > ECSHOP中實(shí)現(xiàn)ajax彈窗登錄功能

ECSHOP中實(shí)現(xiàn)ajax彈窗登錄功能

熱門標(biāo)簽:怎樣在地圖標(biāo)注文字 中國地圖標(biāo)注不明確情況介紹表 東平縣地圖標(biāo)注app 上海企業(yè)外呼系統(tǒng)價(jià)錢 地圖標(biāo)注推銷坑人 河間市地圖標(biāo)注app 立陶宛地圖標(biāo)注 大眾點(diǎn)評400電話怎么申請 電銷機(jī)器人 長春

在上篇文章給大家介紹了使用openSpeDiv方法實(shí)現(xiàn)Ecshop登錄彈窗框效果,大家點(diǎn)擊參考下

下面介紹如何實(shí)現(xiàn)AJAX彈窗登錄。

在ECSHOP中的user.PHP中有處理用戶登錄的請求。

/* 處理 ajax 的登錄請求 */ 
elseif ($action == 'signin') 
{ 
 include_once('includes/cls_json.php'); 
 $json = new JSON; 
 $username = !empty($_POST['username']) ? json_str_iconv(trim($_POST['username'])) : ''; 
 $password = !empty($_POST['password']) ? trim($_POST['password']) : ''; 
 $captcha = !empty($_POST['captcha']) ? json_str_iconv(trim($_POST['captcha'])) : ''; 
 $result = array('error' => 0, 'content' => ''); 
 $captcha = intval($_CFG['captcha']); 
 if (($captcha  CAPTCHA_LOGIN)  (!($captcha  CAPTCHA_LOGIN_FAIL) || (($captcha  CAPTCHA_LOGIN_FAIL)  $_SESSION['login_fail'] > 2))  gd_version() > 0) 
 { 
  if (empty($captcha)) 
  { 
   $result['error'] = 1; 
   $result['content'] = $_LANG['invalid_captcha']; 
   die($json->encode($result)); 
  } 
  /* 檢查驗(yàn)證碼 */ 
  include_once('includes/cls_captcha.php'); 
  $validator = new captcha(); 
  $validator->session_word = 'captcha_login'; 
  if (!$validator->check_word($_POST['captcha'])) 
  { 
   $result['error'] = 1; 
   $result['content'] = $_LANG['invalid_captcha']; 
   die($json->encode($result)); 
  } 
 } 
 if ($user->login($username, $password)) 
 { 
  update_user_info(); //更新用戶信息 
  recalculate_price(); // 重新計(jì)算購物車中的商品價(jià)格 
  $smarty->assign('user_info', get_user_info()); 
  $ucdata = empty($user->ucdata)? "" : $user->ucdata; 
  $result['ucdata'] = $ucdata; 
  $result['content'] = $smarty->fetch('library/member_info.lbi'); 
 } 
 else 
 { 
  $_SESSION['login_fail']++; 
  if ($_SESSION['login_fail'] > 2) 
  { 
   $smarty->assign('enabled_captcha', 1); 
   $result['html'] = $smarty->fetch('library/member_info.lbi'); 
  } 
  $result['error'] = 1; 
  $result['content'] = $_LANG['login_failure']; 
 } 
 die($json->encode($result)); 
} 

把上面這段代碼修改一下,刪掉需要驗(yàn)證碼的部分

改成

/* 處理 ajax彈窗登錄請求 */ 
elseif ($action == 'ajax_login') 
{ 
 include_once('includes/cls_json.php'); 
 $json = new JSON; 
 $username = !empty($_POST['username']) ? json_str_iconv(trim($_POST['username'])) : ''; 
 $password = !empty($_POST['password']) ? trim($_POST['password']) : ''; 
 $result = array('error' => 0, 'content' => ''); 
 $captcha = intval($_CFG['captcha']); 
 if ($user->login($username, $password)) 
 { 
  update_user_info(); //更新用戶信息 
  recalculate_price(); // 重新計(jì)算購物車中的商品價(jià)格 
  $smarty->assign('user_info', get_user_info()); 
  $ucdata = empty($user->ucdata)? "" : $user->ucdata; 
  $result['ucdata'] = $ucdata; 
  $result['content'] = $smarty->fetch('library/member_info.lbi'); 
 } 
 else 
 { 
  $result['error'] = 1; 
  $result['content'] = $_LANG['login_failure']; 
 } 
 die($json->encode($result)); 
} 

// 不需要登錄的操作或自己驗(yàn)證是否登錄(如ajax處理)的act 
$not_login_arr = 
array('login','act_login','register','act_register','act_edit_password','get_password','send_pwd_email','password', 'signin', 'add_tag', 'collect', 'return_to_cart', 'logout', 'email_list', 'validate_email', 'send_hash_mail', 'order_query', 'is_registered', 'check_email','clear_history','qpassword_name', 'get_passwd_question', 'check_answer'); 

改成

// 不需要登錄的操作或自己驗(yàn)證是否登錄(如ajax處理)的act 
$not_login_arr = 
array('ajax_login','login','act_login','register','act_register','act_edit_password','get_password','send_pwd_email','password', 'signin', 'add_tag', 'collect', 'return_to_cart', 'logout', 'email_list', 'validate_email', 'send_hash_mail', 'order_query', 'is_registered', 'check_email','clear_history','qpassword_name', 'get_passwd_question', 'check_answer'); 

common.js文件下,

在openLginDiv()方法里,將newDiv.innerHTML的HTML代碼修改下,在登錄框標(biāo)簽里加個(gè)ajaxLoginSubmit()方法。

//生成層內(nèi)內(nèi)容 
 newDiv.innerHTML = 'form id="ajax_loginForm">用戶名:br>input type="text" name="username" id="ajax_username"/>密碼:br>input type="password" name="password" id="ajax_password"/>br>br>button type="button" onclick="ajaxLoginSubmit()">登錄/button> button type="button" onclick="closeLoginForm()">關(guān)閉/button>/form>'; 

再自己寫兩個(gè)方法即可

function ajaxLoginSubmit(){ 
 var username = document.getElementById('ajax_username').value; 
 var password = document.getElementById('ajax_password').value; 
 Ajax.call('user.php?act=ajax_login','username='+username+'password='+password,ajaxLoginResponse,'POST','JSON'); 
} 
function ajaxLoginResponse(result){ 
 if(result.error == 0){ 
  alert('登錄成功'); 
 }else{ 
  alert('登錄失敗'); 
 } 
 return false; 
} 

以上所述是小編給大家介紹的ECSHOP中實(shí)現(xiàn)ajax彈窗登錄功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

您可能感興趣的文章:
  • javascript實(shí)現(xiàn)ecshop搜索框鍵盤上下鍵切換控制
  • 使用openSpeDiv方法實(shí)現(xiàn)Ecshop登錄彈窗框效果

標(biāo)簽:玉樹 銅川 四川 遼寧 內(nèi)江 益陽 營口 本溪

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ECSHOP中實(shí)現(xiàn)ajax彈窗登錄功能》,本文關(guān)鍵詞  ECSHOP,中,實(shí)現(xiàn),ajax,彈窗,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ECSHOP中實(shí)現(xiàn)ajax彈窗登錄功能》相關(guān)的同類信息!
  • 本頁收集關(guān)于ECSHOP中實(shí)現(xiàn)ajax彈窗登錄功能的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章