使用类定义增删改查接口

This commit is contained in:
2025-11-15 00:05:27 +08:00
parent 5ba11b59db
commit e3cf21d159
7 changed files with 159 additions and 10 deletions

45
templates/user_edit.html Normal file
View File

@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>编辑用户</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
</head>
<body>
<h2>编辑用户</h2>
<form action="#">
<input type="text" name="id" value="{{ user.id }}" style="display: none">
姓名: <input type="text" name="name" value="{{ user.name }}"> <br>
城市: <input type="text" name="city" value="{{ user.city }}"> <br>
性别: <input type="text" name="sex" value="{{ user.sex }}"> <br>
年龄: <input type="text" name="age" value="{{ user.age }}"> <br>
<input type="submit" value="提交" id="btn"> <br>
</form>
<script>
$('#btn').click(function (){
var id = $('input[name=id]').val();
var name = $('input[name=name]').val();
var city = $('input[name=city]').val();
var sex = $('input[name=sex]').val();
var age = $('input[name=age]').val();
data = {'id':id, 'name':name, 'city': city, 'sex': sex, 'age': age};
$.ajax({
type: 'PUT',
url: '/myapp/user/',
data: data,
success: function (result){
if(result.code == 200){
alert('更新用户成功')
location.reload()
}else{
alert('更新用户失败')
}
},
error: function (){
alert('服务器接口异常')
}
})
})
</script>
</body>
</html>