function test(){
alert("123")
var xhr = new XMLHttpRequest();
//发送异步请求
var url='/efficiency/web/selectDeptByCity';
xhr.open("POST",url,true);
var deptcode= document.getElementById("city").value;
var formData = new FormData();
formData.append('deptcode', deptcode);
//发送请求
xhr.send(formData);
//回调函数
xhr.onreadystatechange=function () {
// 通信成功时,状态值为4
if (xhr.readyState === 4){
if (xhr.status === 200){
alert(xhr.responseText);
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
}
原文 https://blog.csdn.net/u012060033/article/details/89958461