标签:方式 function class cti == document 请求响应 span res
使用形式如下:
function showli_1(){ //通过一个按钮onclick触发函数
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","/ajax_js_war_exploded/EmpServlet?flag=1",true);//定义上传的方式,要传输的Servlet和?后加要传输的数据,数据之间以逗号分隔开,定义是否为异步
xmlhttp.send(); //将请求发送
xmlhttp.onreadystatechange=function () { //交互成功后触发的函数
if(xmlhttp.readyState==4&&xmlhttp.status==200){ //接收服务器端的响应(readyState=4表示请求已完成且响应已就绪 status=200表示请求响应一切正常)
document.getElementsByClassName("first")[0].innerHTML=xmlhttp.responseText; //responseText返回的是字符串类型的数据
}
}
}
标签:方式 function class cti == document 请求响应 span res
原文地址:https://www.cnblogs.com/shouyaya/p/12044405.html