-
Ajax( AsynchronousJavaScript and XML ): 异步的javascript和XML。
-
Ajax中一个重要的对象是:XMLHttpRequest。
-
Ajax准备向服务器端发送请求:
xmlHttpRequest.open("GET","AjaxServlet",true);
设置回调函数:xmlHttpRequest.onreadystatechange = ajaxcallback;
发送请求:
xmlHttpRequest.send(null);
-
回调函数:
function ajaxcallback(){ if(xmlHttpRequest.readyState == 4){ if(xmlHttpRequest.status == 200){ var responseTxt = xmlHttpRequest.responseText; document.getElementById("showname").innerHTML = responseTxt; } } }
-
使用POST方式请求时需要加:
xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");