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(`
${item}`);}
arr.forEach((item)=>{
$("#student tbody").append(`
${item['序号']}${item['姓名']}${item['年龄']}${item['性别']}${item['学号']}删除
修改
`)
})
}
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("删除失败")
}
}
}
}