ajax的应用示例
本篇内容介绍了“ajax的应用示例”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
创新互联公司是一家专注于网站设计制作、网站制作与策划设计,秦皇岛网站建设哪家好?创新互联公司做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:秦皇岛等地区。秦皇岛做网站价格咨询:18982081108
Web Tools--Ajax Version
天气预报: value=北京> id=Disp_Weather>
IP地址查询: value=127.0.0.1> id=Disp_IPArea>
手机归属查询:
id=Disp_MobileArea>
id=Disp_MobileArea>
//针对不同的浏览器获取指定的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(".");
if (ipArray.length != 4) {
return false;
}
for (var i = 0; i < 4; i++) {
if (ipArray[i].length == 0 || ipArray[i] > 255) {
return false;
}
}
return true;
}
function getIp() {
if (checkip()) {
createXHR();
req.open("GET", "IpSearch.asp?IP=" + getObj("Ip").value, true);
req.send();
req.onreadystatechange = handleStateChange;
} else {
getObj("Disp_IPArea").innerText = "\u8fd4\u56de\u9519\u8bef\uff1a\u4e0d\u662f\u6b63\u786e\u7684ip";
}
}
function handleStateChange() {
if (req.readyState<4){getObj("Disp_IPArea").innerText = "正在查询ip["+getObj("Ip").value+"]..."}
else if (req.readyState == 4 && req.status == 200) {
getObj("Disp_IPArea").innerText = req.responseText;
} else {
getObj("Disp_IPArea").innerText = "\u67e5\u8be2\u8fc7\u7a0b\u51fa\u73b0\u9519\u8bef\uff0c\u8bf7\u91cd\u8bd5\u6216\u8054\u7cfb\u7ba1\u7406\u5458\uff01";
}
}
function checkMobile() {
var sMobile = getObj("Mobile").value;
if (!(/^13[0-9]\d{4,8}$/.test(sMobile))) {
return false;
}
return true;
}
function getMobile() {
if (checkMobile()) {
createXHR();
req.open("GET", "MobileSearch.asp?Mobile=" + getObj("Mobile").value, true);
req.send();
req.onreadystatechange = handleStateChange2;
} else {
getObj("Disp_MobileArea").innerText = "\u8fd4\u56de\u9519\u8bef\uff1a\u4e0d\u662f\u5b8c\u6574\u768411\u4f4d\u624b\u673a\u53f7\u6216\u8005\u6b63\u786e\u7684\u624b\u673a\u53f7\u524d\u4e03\u4f4d";
}
}
function handleStateChange2() {
if (req.readyState<4){getObj("Disp_MobileArea").innerText = "正在查询手机号码["+getObj("Mobile").value+"]..."}
else if (req.readyState == 4 && req.status == 200) {
getObj("Disp_MobileArea").innerText = req.responseText;
} else {
getObj("Disp_MobileArea").innerText = "\u67e5\u8be2\u8fc7\u7a0b\u51fa\u73b0\u9519\u8bef\uff0c\u8bf7\u91cd\u8bd5\u6216\u8054\u7cfb\u7ba1\u7406\u5458\uff01";
}
}
function chgBtnStyle(){
var btn=document.getElementsByTagName("input")
for(var i=0;i
btn[i].className="btnStyle";
}
}
}
“ajax的应用示例”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
当前文章:ajax的应用示例
转载来源:http://pwwzsj.com/article/jppeph.html