var xmlhttp; if (window.XMLHttpRequest) { // code for modern browsers xmlhttp = new XMLHttpRequest(); } else { // code for old IE browsers xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.open("GET", "demo_get.asp", true); xmlhttp.send(); //或者 xmlhttp.open("POST", "demo_post.asp", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send("fname=Bill&lname=Gates");
xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("myDiv").innerHTML = this.responseText; } };
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
var xmlhttp; if (window.XMLHttpRequest) { // code for modern browsers xmlhttp = new XMLHttpRequest(); } else { // code for old IE browsers xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("myDiv").innerHTML = this.responseText; } }; xmlhttp.open("GET", "demo_get.asp", true); xmlhttp.send();以上就是关于JavaScript中的AJAX请求和响应处理的详细介绍,逐步学习以上步骤,相信大家都能轻松掌握AJAX的使用方法。
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com