1.原生ajax
function loadXMLDoc()
{
var xmlhttp;
//不同浏览器创建对象的函数不同
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
xmlhttp=new XMLHttpRequest();
}
else
{
// IE6, IE5 浏览器执行代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
// XMLHttpRequest 的状态。从 0 到 4 发生变化。4是请求已完成,且响应已就绪,状态为200是ok
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//绑定控件id,如果服务器请求的不是xml文件,请使用 responseText 属性
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","/try",true);
//
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
//只有post方式才能在send()里传值
xmlhttp.send("id=1");
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">请求数据</button>
<div id="myDiv"></div>
我只是个刚学js的菜鸟,如有问题,请指出
以上