Crowdfunding:Role maintenance update

折月煮酒 提交于 2020-01-19 03:10:26

一、大致步骤

1、给更新按钮绑定单击响应函数,因为更新按钮是动态生成的,所以需要使用on()方式。

2、打开模态框:把roleId保存到全局变量,获取当前按钮所在行的roleName,使用roleName回显模态框中的表单。

3、给模态框中的保存按钮绑定单击响应函数:收集文本框内存、发送请求、请求处理完成关闭模态框、重新分页。

 

二、打开模态框并回显表单

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div id="editModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form role="form">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">众筹网系统弹框</h4>
                </div>
                <div class="modal-body">
                    <input type="text"
                           id="roleNameInputedit"
                           class="form-control" placeholder="请输入角色名称"/>
                </div>
                <div class="modal-footer">
                    <button id="editModalBtn" type="button" class="btn btn-success">
                        <i class="glyphicon glyphicon-edit"></i>edit</button>
                    <button type="reset" class="btn btn-primary">
                        <i class="glyphicon glyphicon-refresh"></i>
                        reset</button>
                </div>
            </form>
        </div>
    </div>
</div>

三、执行更新

$("#editModalBtn").click(function () {

    //1、获取文本框值
    var roleName = $.trim($("#roleNameInputedit").val());
    if (roleName == null || roleName == ""){
        layer.msg("请输入有效角色名称!");
        return ;
    }
    //2、发送请求
    $.ajax({
        "url":"role/update/role.json",
        "type":"post",
        "data":{
            "id":window.roleId,
            "name":roleName
        },
        "dataType":"json",
        "success":function (response){
            var result = response.result;
            if (result == "SUCCESS"){
                layer.msg("操作成功!");
                showPage();
            }
            if (result == "FAILED"){
                layer.msg(response.message);
            }
            $("#editModal").modal("hide");
        },
        "error":function (response) {
            layer.msg(response.message);
        }
    });
});

handler:

impl:

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!