<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="day1.html">woshi a </a>
<table id="student">
<thead>
<tr></tr>
</thead>
<tbody>
</tbody>
</table>
<script src="../js/jquery-1.11.3.js"></script>
<script>
window.function () {
getData();
}
//1.11请求数据
function getData() {
if(window.XMLHttpRequest){
var XHR = new XMLHttpRequest()
}else{
var XHR = new ActiveXObject("Microsoft.XMLHTTP")
}
//1.12 打开ajax对象3参数(请求方式,请求地址,同步(flase)异步(ture)布尔值)
XHR.open("get","/login.do",true)
//1.3 AJAX 结束请求
XHR.send()
XHR.onreadystatechange=function () {
if(XHR.readyState==4&&XHR.status==200){
let arr=JSON.parse(XHR.responseText)
onloadIndex(arr)
}
}
//1.4利用AJAX 对象发送对象
}
function onloadIndex(arr) {
$("#student thead>tr").html("");
$("#student tbody").html("");
for(item in arr[0]){
$("#student thead>tr").append(`<th>${item}</th>`);
}
arr.forEach((item)=>{
$("#student tbody").append(`
<tr>
<td>${item['序号']}</td>
<td>${item['姓名']}</td>
<td>${item['年龄']}</td>
<td>${item['性别']}</td>
<td>${item['学号']}</td>
<td>
<button onclick="deleBtn('${item['学号']}')">删除</button>
<button>修改</button>
</td>
</tr>
`)
})
}
function deleBtn(stuId){
if(window.XMLHttpRequest){
var XHR = new XMLHttpRequest()
}else{
var XHR = new ActiveXObject("Microsoft.XMLHTTP")
}
XHR.open("post","/login_one.do",true)
XHR.setRequestHeader("content-type","application/x-www-form-urlencoded")
XHR.send("stuId="+stuId);
XHR.onreadystatechange=function () {
if(XHR.readyState==4&&XHR.status==200){
let stu=Boolean(XHR.responseText)
if(stu){
getData()
}else{
alert("删除失败")
}
}
}
}
</script>
</body>
</html>
ajax删除 post方法
猜你喜欢
转载自blog.csdn.net/weixin_43453916/article/details/85704025
今日推荐
周排行