ajax初步了解
一、什么是ajax <script type="text/javascript"> var xmlHttp=null; function loadContext(url,fuc) { if(window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); }else{ xmlHttp = new ActiveXObject(); } xmlHttp.onreadystatechange=fuc; xmlHttp.open("GET",url,true); xmlHttp.send(); } function myFunction(){ loadContext("/ajax",function () { if(xmlHttp.readyState==4 && xmlHttp.status==200){ document.getElementById("myDiv").innerHTML = xmlHttp.responseText; } }); } </script>
jsp布局 <div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="myFunction()">通过AJAX更新页面</button>
Servlet内容 response.setContentType("text/plain");
response.getWriter().write("BeiJing welcome you");
2.基于jquery的ajax 常见四种方式:
function myFunction(){
$.ajax({
type:"GET",url:"/ajax",dataType:"text",success:function(result){
document.getElementById("myDiv").innerHTML = result;
}
})
}
三、小结 通过以上的总结,对ajax有了自己的认识,内容不多,但是功能挺强大的 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |