var xmlhttp;
if (window.XMLHttpRequest) //火狐,谷歌等高级浏览器
{
xmlhttp = new XMLHttpRequest();
}
else //IE5,IE6等渣渣浏览器
{
xmlhttp = ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
//do something like $("#ID").innerHTML = xmlhttp.responseText;
}
}
POST请求:
xmlhttp.open("POST","/user.action",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmhttp.send("username=yuangs&pwd=123")
GET请求:
xmlhttp.open("GET","/user.action?username=yuangs&pwd=123",true)
xmlhttp.send()
网友评论