当前位置:首页 > Web开发 > 正文

dataType: ‘ json ‘

2024-03-31 Web开发

<script> function saveData() { $.ajax({ url: https://localhost:44368/api/UserInfo/Add, type: post, data: {UName:$("#UName").val(),Pass:$("#Pass").val()}, dataType: json, success: function (data) { if (data > 0) { alert(添加告成); location.href = "/default/index"; } } }); } </script>

显示、删除

<script> LoadData(); function LoadData() { $.ajax({ url: https://localhost:44368/api/UserInfo/GetAll, type: get, data: {}, dataType: json, success: function (data) { $("#tb").empty(); $(data).each(function () { $("#tb").append(<tr><td> + this.UId + </td><td> + this.UName + </td><td> + this.Pass + </td><td><input type="button" value="改削"color: #800000;">‘ + this.UId + )"/><input type="button" value="删除"color: #800000;">‘+this.UId+)"/></td></tr>); }); } }); } function Edit(Id) { location.href = "/Default/Edit/" + Id; } function Del(Id) { if (confirm("确认删除么?")) { $.ajax({ url: https://localhost:44368/api/UserInfo/Remove/+Id, type: post, data: {}, dataType: json, success: function (data) { if (data > 0) { alert(删除告成); LoadData();//刷新页面 } } }); } } </script> }

改削

<script> var UId = @ViewData["UId"]; LoadData(); function saveData() { $.ajax({ url: https://localhost:44368/api/UserInfo/Edit, type: post, data: {UId:$("#UId").val(),UName:$("#UName").val(),Pass:$("#Pass").val()}, dataType: json, success: function (data) { if (data > 0) { alert(改削告成); location.href = "/default/index"; } } }); } function LoadData() { $.ajax({ url: https://localhost:44368/api/UserInfo/GetUserById/+UId, type: get, data: {}, dataType: json, success: function (data) { $("#UId").val(data.UId); $("#UName").val(data.UName); $("#Pass").val(data.Pass); } }); } </script>

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30007.html