这次给大家带来ajax基本通用代码有哪些,使用ajax基本通用代码的注意事项有哪些,下面就是实战案例,一起来看一下。
本文实例讲述了ajax基本通用代码。分享给大家供大家参考,具体如下:
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)
}
}
}
Click
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读: