前端页面

<a href="javascript:void(0);" onclick="changPassword()">
  <i class="ace-icon fa fa-cog"></i>
  修改密码
</a>

<script type="text/javascript">
  //打开模态框
  function changPassword(){
    $("#navbar_edit").modal({
      backdrop :'static'
    });
  }
</script>
<#include "/include/navbar_edit.html">

<!-- 模态框(Modal) -->
<div class="modal fade" id="navbar_edit" tabindex="-1" role="dialog"
  aria-labelledby="roleEditLabel" aria-hidden="true">
  <div class="modal-dialog" style="width:500px;">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title" id="roleEditLabel">修改密码</h4>
      </div>
      <div class="modal-body">
      <div style="width:90%;">
        <form class="form-horizontal" id="navbar_pwd_reset">
          <div class="form-group">
            <label class="col-sm-4 control-label" for="old_password">旧密码:</label>
            <div class="col-sm-8" style="padding:0">
            <input class="col-sm-12" type="password" id="old_password"
              name="old_password" placeholder="请输入旧密码 " />
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-4 control-label" for="new_password">新密码:</label>
            <div class="col-sm-8" style="padding:0">
            <input class="col-sm-12" type="password" id="new_password"
              name="new_password" placeholder="请输入新密码 " />
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-4 control-label" for="confirm_password">确认新密码:</label>
            <div class="col-sm-8" style="padding:0">
              <input class="col-sm-12" type="password" id="confirm_password"
                name="confirm_password" placeholder="确认新密码 " />
            </div>
          </div>
        </form>
      </div>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-xs btn-default"
          data-dismiss="modal" id="navbar_close_btn">
        <i class="ace-icon fa fa-times bigger-110"></i> <span
          class="bigger-110 no-text-shadow">关闭</span>
      </button>
      <button type="button" class="btn btn-xs btn-primary" id="navbar_save_btn">
        <i class="ace-icon fa fa-floppy-o bigger-110"></i> <span
          class="bigger-110 no-text-shadow">保存</span>
      </button>
    </div>
   </div>
    <!-- /.modal-content -->
  </div>
<!-- /.modal -->
</div>

<script type="text/javascript">
  $("#navbar_edit").on("show.bs.modal", function() {
    $("#navbar_edit #navbar_pwd_reset").formClear();

  });
  $("#navbar_edit").on("hidden.bs.modal", function() {
    $(this).removeData("bs.modal");

  });
  $(document).on("click", "#navbar_save_btn", function(e) {
    var old_psd = $("#navbar_pwd_reset #old_password").val();
    var new_psd = $("#navbar_pwd_reset #new_password").val();
    var con_psd = $("#navbar_pwd_reset #confirm_password").val();
    //alert(old_psd);
    //alert(new_psd);
    //alert(con_psd);
    if (old_psd == "" || new_psd == "" || con_psd == "") {
    bootbox.alert("相关字段不为空,请输入!");
      return false;
    };
    if (old_psd == new_psd) {
    bootbox.alert("旧密码和新密码相同,请重新输入!");
      return false;
    };
    if (new_psd != con_psd) {
      bootbox.alert("两次输入新密码不相同,请重新输入!");
      return false;
    };
    var params = $("#navbar_pwd_reset").serialize();
      //alert(params);
      $.ajax({
        cache : true,
        type : "POST",
        url : "${ctx!}/modifyPassword",
        data : params,
        async : false,
        error : function(request) {
          bootbox.alert("服务器连接错误,请稍后再试");
        },
        success : function(data) {
          if (SQ.isOK(data)) {
            bootbox.alert("重置成功", function() {
              $("#navbar_close_btn").click();
            });
          } else {
            bootbox.alert("重置失败:" + SQ.getMessage(data));
          }
        },
      });
    });
</script>

后端页面

public void modifyPassword() {
  BasMember sysUser = this.getLoginUser();

  if (sysUser == null || sysUser.getInt(BasMember.IsDelete).equals(1)) {
    render(new JsonRender(new AjaxResult(Constants.RESPONSE_STATUS_FAIL, "会话已过期,请重新登录!")).forIE());
    return;
  }

  // 旧秘密
  String password = getPara("old_password");
  password = CommonUtil.getEncryptedPwd(password);
  if (!password.equals(sysUser.get(BasMember.Password))) {
    render(new JsonRender(new AjaxResult(Constants.RESPONSE_STATUS_FAIL, "旧密码不正确!")).forIE());
    return;
  }

  // 新密码
  password = getPara("new_password");
  password = CommonUtil.getEncryptedPwd(password);

  // 赋值
  sysUser.set(BasMember.Password, password);
  sysUser.set(BasMember.ModifyBy, this.getLoginId());
  sysUser.set(BasMember.ModifyTime, StringUtil.getNowTime());
  if (!sysUser.update()) {
    render(new JsonRender(new AjaxResult(Constants.RESPONSE_STATUS_FAIL, "修改时出现异常")).forIE());
  }
  render(new JsonRender(new AjaxResult(Constants.RESPONSE_STATUS_OK, "修改成功!")).forIE());
}

使用ajax请求,模态框调用并更改密码的更多相关文章

  1. Ajax技术使用之ajax与模态框结合的妙用

    Ajax技术使用之ajax与模态框结合的妙用 要求: 使用ajax的方式提交数据:https://www.cnblogs.com/-wenli/p/10470063.html 使用模态框完成增加数据, ...

  2. ajax+json模态框中分页(spring+struts+mybatis+easyui分页插件)

    0.业务需求: 点击每个数字的时候可以显示每个对应的详细记录.也就是得点击11的时候拿着开采部与C级去查询.

  3. ajax请求,html调用js

    1:html中调用js中的函数,js使用ajax请求向后台请求,返回数据. <!DOCTYPE html> <html lang="en"> <hea ...

  4. ajax 请求发出了,数据更改了,但是没进入success 函数 把success 换成 complete

    $(function(){ $(document).on('tap','.w-location-group .mui-table-view-cell',function(){ var bool = $ ...

  5. jQuery delegate方法实现Ajax请求绑定事件不丢失

    给元素绑定click事件后 ,遇到一个问题:当执行一些ajax请求,再次调用此页面,里面的这个click事件就失效了 比如说:我的分页是一个ajax请求 但我点下一页时 后生成的元素a就没有了clic ...

  6. Ajax请求过程中显示“进度”的简单实现

    Ajax在Web应用中使用得越来越频繁.在进行Ajax调用过程中一般都具有这样的做法:显示一个GIF图片动画表明后台正在工作,同时阻止用户操作本页面(比如Ajax请求通过某个按钮触发,用户不能频繁点击 ...

  7. Ajax发送请求等待时弹出模态框等待提示

    主要的代码分为两块,一个是CSS定义模态框,另一个是在Ajax中弹出模态框. 查看菜鸟教程中的模态框教程demo,http://www.runoob.com/try/try.php?filename= ...

  8. bootstrap模态框动态赋值, ajax异步请求数据后给id为queryInfo的模态框赋值并弹出模态框(JS)

    /查询单个 function query(id) { $.ajax({ url : "/small/productServlet", async : true, type : &q ...

  9. bootstrap通过ajax请求JSON数据后填充到模态框

    1.   JSP页面中准备模态框 <!-- 详细信息模态框(Modal) --> <div> <div class="modal fade" id=& ...

随机推荐

  1. git 使用钩子直接推送到工作目录

    远端机器 $ mkdir /www/teacherapi  # 创建工作目录 $ cd /data/git $ git init teacherapi.git --bare --shared Init ...

  2. LR调用动态链接库DLL

    什么是动态库? 动态库一般又叫动态链接库(DLL),是Dynamic Link Library 的缩写形式,DLL是一个包含可由多个程序同时使用的代码和数据的库. 动态链接提供了一种方法 ,使进程可以 ...

  3. xml提取

    $url = 'http://221.232.141.108/hsdcw/news.xml'; $opts = array( 'http'=>array( 'method'=>" ...

  4. 2014总结&2015计划

    2014总结&2015计划 今天是2015/1/1,新的一年终于到来了,昨天老板要求提交2014的工作总结和2015的工作计划,正好提醒我,要总结和计划了. 先回顾2014年初的计划: 新年计 ...

  5. Java 常见问题思考

    Java中的成员变量是选择在声明时赋值还是在构造函数中赋值? // 通过构造函数赋值 public class UserRequestImpl extends ModuleImplBase { pri ...

  6. epoll 实际使用

    void DataHandle::recv() {     sleep(2);     _data_router -> readInfoHw(&mInfo);     ALOGD(SYS ...

  7. 低功耗蓝牙4.0BLE编程-nrf51822开发(11)-蓝牙串口代码分析

    代码实例:点击打开链接 实现的功能是从uart口发送数据至另一个蓝牙串口,或是从蓝牙读取数据通过uart打印出数据. int main(void) { // Initialize leds_init( ...

  8. ManualResetEvent和AutoResetEvent的区别实例

    ManualResetEvent和AutoResetEvent的作用可以理解为在线程执行中插入停顿点flag终止程序运行,然后通过设置flag的状态来使得程序继续运行. 两者的区别是:ManualRe ...

  9. Qt StyleSheet皮肤(黑色,比较好看,而且很全)

    使用方式如下 //设置皮肤样式 static void SetStyle(const QString &styleName) { QFile file(QString(":/imag ...

  10. Qt 窗口属性简介之Qt::WA_DeleteOnClose

    一.简述 今天介绍一个简单的窗口属性——Qt::WA_DeleteOnClose. 在正常创建窗口后,我们一般会调用close()方法来关闭窗口,这里我们看一下Q助手中关于close()方法的介绍. ...