//这里是一个查询
function selectData() {
$('#searchbtn').click(function () {
var searchKey = $('#search').val();
let classID = $('#selClass').val();
var xhr;
//1、建立连接
if (XMLHttpRequest) {
xhr = new XMLHttpRequest;
} else {
xhr = new ActiveXObject('Micosoft.HTTPXML');
}
//2、打开连接
xhr.open('get', '/student/search?name=' + searchKey + '&classID=' + classID);
//3、状态改变时的操作多为DOM
xhr.onreadystatechange = function () {
//状态为4,状态码为200表示成功
if (xhr.readyState == 4 && xhr.status == 200) {
let result = JSON.parse(xhr.responseText);
if (result.code == 200) {
student = result.data;
displayData();
} else {
alert(result.message);
}
}
}
//4、发送请求
xhr.send(null);
})
ajax使用
最新推荐文章于 2024-09-09 18:35:55 发布