<html> <head> <script type="text/javascript"> var xmlHttpRequest = null;//声明一个空对对象以接受XMLHttpRequest 对象 function ajaxSubmit() { if(window.ActiveXObject) { xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器 } else if (window.XMLHttpRequest){ xmlHttpRequest = new XMLHttpRequest();//非IE浏览器 } if(null != xmlHttpRequest) { xmlHttpRequest.open("GET", "AjaxServlet", true); //关联好回调函数 xmlHttpRequest.onreadystatechange = ajaxCallBack; //向服务器发送数据,发送请求提的内容get 请求时,为null xmlHttpRequest.send(null); } } function ajaxCallBack() { if(xmlHttpRequest.readyState == 4) { if(xmlHttpRequest.status == 200) { var responseText = xmlHttpRequest.responseText; document.getElementById("div1").innerHTML = responseText; } } } </script> </head> <body> <input type="button" value="get value from servlet" οnclick="ajaxSubmit()"> <div id="div1"></div> </body> </html>
javascript 实现 ajax 示例代码----get方式
最新推荐文章于 2017-03-19 15:00:04 发布