這篇文章將為大家詳細(xì)講解有關(guān)ECSHOP中如何實現(xiàn)ajax彈窗登錄功能,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

十余年的濉溪網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。營銷型網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整濉溪建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)公司從事“濉溪網(wǎng)站設(shè)計”,“濉溪網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。
在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));
}
/* 檢查驗證碼 */
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(); // 重新計算購物車中的商品價格
$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));
}把上面這段代碼修改一下,刪掉需要驗證碼的部分
改成
/* 處理 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(); // 重新計算購物車中的商品價格
$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));
}將
// 不需要登錄的操作或自己驗證是否登錄(如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');改成
// 不需要登錄的操作或自己驗證是否登錄(如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)簽里加個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>';
再自己寫兩個方法即可
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;
}關(guān)于“ECSHOP中如何實現(xiàn)ajax彈窗登錄功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
當(dāng)前文章:ECSHOP中如何實現(xiàn)ajax彈窗登錄功能
鏈接URL:http://www.chinadenli.net/article30/iiespo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、網(wǎng)站策劃、網(wǎng)站營銷、網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)