1 function fn1(){ 2 ????????//1、创建ajax引擎对象 ---- 所有的操作都是通过引擎对象 3 ????????var xmlHttp = new XMLHttpRequest(); 4 ????????//2、绑定监听 ---- 监听服务器是否已经返回相应数据 5 ????????xmlHttp.onreadystatechange = function(){ 6 ????????????if(xmlHttp.readyState==4&&xmlHttp.status==200){ 7 ????????????????//5、接受相应数据 8 ????????????????var res = xmlHttp.responseText; 9 ????????????????document.getElementById("span1").innerHTML = res;10 ????????????}11 ????????}12 ????????//3、绑定地址13 ????????xmlHttp.open("GET","/WEB22/ajaxServlet?name=lisi",true); //true表示是异步14 ????????//4、发送请求15 ????????xmlHttp.send();16 ????????17 ????}
原生ajax
原文地址:https://www.cnblogs.com/Allen-Wei/p/8994421.html