鉴于大家对Ajax十分关注,我们编辑小组在此为大家搜集整理了“ajax应用”一文,供大家参考学习
<DIV class=box id=top_bar>Web Tools--Ajax Version </DIV><BR>
<DIV class="box general"> 天气预报: <INPUT id=Weather size=17
value=北京> <INPUT onclick=getWeather() type=button value="提 交" name=submit> <SPAN
id=Disp_Weather></SPAN></DIV>
<DIV class="box general"> IP地址查询: <INPUT id=Ip maxLength=17 size=17
value=127.0.0.1> <INPUT onclick=getIp() type=button value="提 交" name=submit> <SPAN
id=Disp_IPArea></SPAN></DIV>
<DIV class="box general">手机归属查询: <INPUT id=Mobile maxLength=15 size=17 value=13>
<INPUT onclick=getMobile() type=button value="提 交"> <SPAN
id=Disp_MobileArea></SPAN></DIV>
<SCRIPT language=JavaScript type=text/javascript>
chgBtnStyle();
</SCRIPT>
//针对不同的浏览器获取指定的id对象
function getObj(objID) {
return document.all ? document.all[objID] : document.getElementById(objID);
}
var req;
//使用xmlrequest对象
function createXHR() {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E) {
req = false;
}
}
if (!req && typeof XMLHttpRequest != "undefined") {
req = new XMLHttpRequest();
}
}
function getWeather() {
createXHR();
req.open("GET", "weather.asp?City=" + getObj("Weather").value, true);
req.send();
req.onreadystatechange = handleStateChange1;
}
function handleStateChange1() {
if (req.readyState<4){getObj("Disp_Weather").innerText = "正在查询["+getObj("Weather").value+"]天气状况..."}
else if (req.readyState == 4 && req.status == 200) {
getObj("Disp_Weather").innerText = req.responseText;
} else {
getObj("Disp_Weather").innerText = "\u67e5\u8be2\u8fc7\u7a0b\u51fa\u73b0\u8fc7\u7a0b\uff0c\u8bf7\u91cd\u8bd5\u6216\u8054\u7cfb\u7ba1\u7406\u5458\uff01";
}
}
function checkip() {
var ipArray, ip, j;
ip = getObj("Ip").value;
if (/[^\d\.]/.test(ip)) {
return false;
}
ipArray = ip.split(".");
&