Ajax Application _ajax Related

Source: Internet
Author: User

<div class=box id=top_bar>web tools--ajax Version </DIV><BR>
<div class= "box General" > Weather forecast: <input id=weather size=17
Value= Beijing > <input onclick=getweather () Type=button value= "Submit" name=submit> <span
Id=disp_weather></span></div>
<div class= "Box General" > Ip address query: <input id=ip maxlength=17 size=17
Value=127.0.0.1> <input onclick=getip () Type=button value= "Submit" name=submit> <span
Id=disp_iparea></span></div>
<div class= "box General" > Mobile phone Attribution query: <input id=mobile maxlength=15 size=17
<input onclick=getmobile () Type=button value= "Submit" > <span
Id=disp_mobilearea></span></div>
<script Language=javascript type=text/javascript>
Chgbtnstyle ();
</SCRIPT>
Get the specified ID object for a different browser
function Getobj (ObjID) {
return document.all? Document.all[objid]: document.getElementById (ObjID);
}
var req;
Using the XMLRequest object
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 = "is querying [" +getobj ("Weather"). Value+ "] weather conditions ..."}
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 = "Querying 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 = "is querying mobile phone number [" +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.length;i++) {
        if ( btn[i].type== ' button ') {
           btn[i].classname= Btnstyle ";
       }
   }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.