时间:2021-07-01 10:21:17 帮助过:3人阅读
本文实例讲述了ajax基本通用代码。分享给大家供大家参考,具体如下:
<html>
<head>
<script type="text/JavaScript">
var xmlhttp
function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
xmlhttp.onreadystatechange=state_Change
xmlhttp.open("GET",url,true)
xmlhttp.send(null)
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
xmlhttp.onreadystatechange=state_Change
xmlhttp.open("GET",url,true)
xmlhttp.send()
}
}
}
function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
// if "OK"
if (xmlhttp.status==200)
{
document.getElementById('T1').innerHTML=xmlhttp.responseText
}
else
{
alert("Problem retrieving data:" + xmlhttp.statusText)
}
}
}
</script>
</head>
<body onload="loadXMLDoc('test_xmlhttp.txt')">
<p id="T1" style="border:1px solid black;height:40;width:300"></p><br />
<button onclick="loadXMLDoc('test_xmlhttp2.txt')">Click</button>
</body>
</html>相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
JSONP怎么处理Ajax的跨域访问
ajax操作全局监测,用户session失效怎么处理
以上就是ajax基本通用代码有哪些的详细内容,更多请关注Gxl网其它相关文章!