侯体宗的博客
  • 首页
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

ECSHOP中实现ajax弹窗登录功能

框架(架构)  /  管理员 发布于 7年前   453

在上篇文章给大家介绍了使用openSpeDiv方法实现Ecshop登录弹窗框效果,大家点击参考下

下面介绍如何实现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));   }   /* 检查验证码 */   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代码修改下,在登录框标签里加个ajaxLoginSubmit()方法。

//生成层内内容  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()">关闭</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; } 

以上所述是小编给大家介绍的ECSHOP中实现ajax弹窗登录功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对站的支持!


  • 上一条:
    pjblog实现类似CMS的首页调用
    下一条:
    asp中格式化HTML函数代码 SDCMS加强版
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Filament v3.1版本发布(0个评论)
    • docker + gitea搭建一个git服务器流程步骤(0个评论)
    • websocket的三种架构方式使用优缺点浅析(0个评论)
    • ubuntu20.4系统中宿主机安装nginx服务,docker容器中安装php8.2实现运行laravel10框架网站(0个评论)
    • phpstudy_pro(小皮面板)中安装最新php8.2.9版本流程步骤(0个评论)
    • 近期文章
    • 在go语言中实现字符串可逆性压缩及解压缩功能(0个评论)
    • 使用go + gin + jwt + qrcode实现网站生成登录二维码在app中扫码登录功能(0个评论)
    • 在windows10中升级go版本至1.24后LiteIDE的Ctrl+左击无法跳转问题解决方案(0个评论)
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2018-05
    • 2020-02
    • 2020-03
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-11
    • 2021-03
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-08
    • 2023-08
    • 2023-10
    • 2023-12
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客