AJAX普通增删改查

引用文件

<link href="~/BootstrapSouce/css/bootstrap.css" rel="stylesheet" />
<script src="~/BootstrapSouce/js/bootstrap.min.js"></script>
<script src="~/BootstrapSouce/js/jquery.min.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>

样式

<style>
    th {
    text-align:center;
    }
    td {
        font-size:larger;
        text-align: center;
        color:cornflowerblue;
    }
</style>

显示  删除方法

<div style="width:100%; height:100%; margin: 0 auto; text-align:center; line-height: 200px">
    <table class="table table-striped" >

<thead>
            <tr>
                <th>编号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>用户角色</th>
                <th>用户状态</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody id="div">
           
        </tbody>
    </table>
</div>
<script>

$(function () {
        $.ajax({
            type: "get",
            url: "/UserInfo/UserInfoShowDo",
            success: function (obj) {
                obj = JSON.parse(obj);
                for (var i = 0; i < obj.length; i++) {
                    var gender = "";
                    var state = "";
                    if (obj[i].Gender == 1) {
                        gender = "女";
                    }
                    else {
                        gender = "男";
                    }
                    if (obj[i].UserState == 0) {
                        state = "停用";
                    }
                    else {
                        state = "可用";
                    }
                    $("#div").append("<tr><td>" + obj[i].UserId + "</td><td>" + obj[i].UserName + "</td><td>" + gender + "</td><td>" + obj[i].RoleName + "</td><td>" + state + "</td><td><input type=‘button‘ value=‘删除‘ class=‘btn btn-info‘ onclick = ‘Del(" + obj[i].UserId + ")‘/><input type=‘button‘ value=‘修改‘ class=‘btn btn-info‘  onclick = ‘Upt(" + obj[i].UserId + ")‘/></td></tr>");
                }
            }
        })
    })

function Del(UserId) {
        if (confirm("确定要删除吗?")) {
            $.ajax({
                type: "post",
                url: "/UserInfo/DelUserInfoDo",
                datatype: "json",
                data: { Id: UserId },
                success: function (obj) {
                    if (obj > 0) {
                        alert("删除成功");
                        location.href = "/UserInfo/UserInfoShow";
                    }
                    else {
                        alert("删除失败");
                    }
                }
            })

}
    }

function Upt(UserId) {
        location.href = "/UserInfo/UptUserInfo?id=" + UserId;
    }
</script>

添加方法

<div style="width:50%; margin:auto;text-align:center;padding-top:20px;">
    <div class ="alert alert-success">请添加用户的信息-_-!</div>
   
    <form>
        <table class="table table-striped">
            <tr>
                <td>姓名:</td>
                <td>
                    <input type="text" class="form-control" id="txtname" placeholder="请输入姓名" />
                </td>
            </tr>
           
            <tr>
                <td>密码:</td>
                <td>
                    <input type="text" class="form-control" id="txtpwd" placeholder="请输入密码" />
                </td>
            </tr>
            <tr>
                <td>性别:</td>
                <td>
                    <input id="radio1" type="radio" name="Gender" value="0" checked="checked" /><span>男</span><input id="radio2" type="radio" name="Gender" value="1" /><span>女</span>
                </td>
            </tr>
          
            <tr>
                <td>状态:</td>
                <td>
                    @Html.RadioButton("UserState",1)<span>可用</span>
                    @Html.RadioButton("UserState",0)<span>不可用</span>
                </td>
            </tr>
           
        </table>
        <input id="btn1" type="button" class="btn btn-info" value="添加" />
    </form>
</div>
<script>
    $.ajax({
        type: "post",
        url: "/UserInfo/RoleInfoShowDo",
        datatype: "json",
        success: function (obj) {
            obj = JSON.parse(obj);
            for (var i = 0; i < obj.length; i++) {
                $("#Select1").append("<option value=‘" + obj[i].RoleId + "‘>" + obj[i].RoleName + "</option>")
            }
        }
    })

$("#btn1").click(function () {
        var name = $("#txtname").val();
        var pwd = $("#txtpwd").val();
        var gender = $(":radio:checked").val();
        var roleid = $("#Select1").val();
        var userstate = $("#UserState").val();

if (name == "" || pwd == "" || userstate == "") {
            alert("信息不完整");
            return;
        }
        $.ajax({
            type: "post",
            url: "/UserInfo/AddUserInfoDo",
            datatype: "json",
            data: { UserName: name, PassWord: pwd, Gender: gender, RoleId: roleid, UserState: userstate },
            success: function (obj) {
                if (obj > 0) {
                    alert("添加成功");
                    location.href = "/UserInfo/UserInfoShow";
                }
                else {
                    alert("添加失败");
                }
            }
        })
    })

</script>

修改+返填

<div style="width:50%; margin:auto;text-align:center;padding-top:100px;">
    <div class="alert alert-success">请修改用户的信息-_-!</div>
 
    <form>
        <table>
            <tr>
                <td>编号:</td>
                <td>
                    <input type="text" class="form-control" id="userid" value="@Model.UserId"  readonly="true">
                </td>
            </tr>
            <tr>
                <td>姓名:</td>
                <td>
                    <input type="text" class="form-control" id="txtname" value="@Model.UserName" placeholder="请输入姓名" />
                </td>
            </tr>
            <tr>
                <td>密码:</td>
                <td>
                    <input type="text" class="form-control" id="txtpwd" value="@Model.PassWord" placeholder="请输入密码" />
                </td>
            </tr>
            <tr>
                <td>性别:</td>
                <td>
                    <input id="radio1" type="radio" name="Gender" value="@Model.Gender" checked="checked" /><span>男</span><input id="radio2" type="radio" name="Gender" value="@Model.Gender" /><span>女</span>
                </td>
            </tr>
            <tr>
                <td>角色:</td>
                <td>
                    <select id="Select1" ></select>
                </td>
            </tr>

</table>
        <input id="btn1" type="button" value="修改" />
    </form>
</div>
<script>
    $.ajax({
        type: "post",
        url: "/UserInfo/RoleInfoShowDo",
        datatype: "json",
        success: function (obj) {
            obj = JSON.parse(obj);
            for (var i = 0; i < obj.length; i++) {
                $("#Select1").append("<option value=‘" + obj[i].RoleId + "‘>" + obj[i].RoleName + "</option>")
            }
        }
    })

$("#btn1").click(function () {
        var userid = $("#userid").val();
        var name = $("#txtname").val();
        var pwd = $("#txtpwd").val();
        var gender = $(":radio:checked").val();
        var roleid = $("#Select1").val();

if (name == "" || pwd == "" ) {
            alert("信息不完整");
            return;
        }
        $.ajax({
            type: "post",
            url: "/UserInfo/UptUserInfoDo",
            datatype: "json",
            data: { UserName: name, PassWord: pwd, Gender: gender, RoleId: roleid,UserId:userid },
            success: function (obj) {
                if (obj > 0) {
                    alert("修改成功");
                    location.href = "/UserInfo/UserInfoShow";
                }
                else {
                    alert("修改失败");
                }
            }
        })
    })

</script>

时间: 2024-10-17 21:23:42

AJAX普通增删改查的相关文章

vue实战(一):利用vue与ajax实现增删改查

vue实战(一):利用vue与ajax实现增删改查: <%@ page pageEncoding="UTF-8" language="java" %> <%@ include file="../commons/taglib.jsp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.

ajax参考增删改查

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

AJAX做增删改查详细!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

MVC中的Ajax与增删改查(二)

上一篇记录的是前台操作,下面写一下后台 ,本来自认为是没有必要做补充,毕竟思路啥的都有,实际上在做删除操作的时候,折腾了一天,还是自己太嫩,逻辑不够严谨,这里作下记录. 关于表结构这里再作下说明: ①表A是三个联合主键,key1,key2,... ②表B是四个联合主键 key1,key2,key3,... ③A表主键是B表外键 ④A,B表的某个栏位的描述信息都来自语言表C ⑤C表联合主键(TableName,TableKey,Language,Desc,...) ⑥如果记录A表描述信息: Tab

通过Ajax实现增删改查

项目链接:https://github.com/shuai7boy/Ajax_CRUD 简要截图:

Salesforce零基础(三)简单的数据增删改查页面的构建(Ajax样式)

VisualForce封装了很多的标签用来进行页面设计 下面以一个单一的表进行数据增删改查.表结构如图1所示.通过图可以看出GOODS表自己定义的参数主要包括以下: GoodsName__c,GoodsType__c,GoodsBrand__c,GoodsDescribe__c,GoodsPrice__c. 图1 VF每个页面都是以<apex:page>标签起始</apex:page>结束,每个VF页面都有一个Controller用来控制其业务逻辑.本篇例子中主要用到的控件包括如下

AJAX 调用WebService 、WebApi 增删改查(笔记)

经过大半天努力,终于完成增删改查了!心情有点小激动!!对于初学者的我来说,一路上都是迷茫,坑!!虽说网上有资料,可动手起来却不易(初学者的我).(苦逼啊!) WebService 页面: /// <summary> /// TsetWeb 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.

ajax(3)后台增删改查

注明:原资料:http://www.cnblogs.com/liangxiblog/p/5461205.html<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <link href="css/bootstrap.min.css" rel="stylesheet&qu

框架 day39-42 SSH整合练习项目CRM(配置文件,增删改查,ajax,上传/下载,分页,BaseDao/Action)

1     配置文件 1.1   spring配置 1.1.1       介绍     加载properties     配置数据源DataSource     配置SessionFactory , 加载所有hbm.xml     hibernate事务管理     使用 <import > 所有的模块都使用单独配置文件 1.1.2       使用源码包     使用config源码,将源码和配置文件分开存放,方便程序的维护. 1.1.3       spring核心 1.1.