Getting started with Ajax

Source: Internet
Author: User

<HTML>
<Head>
<Title> Ajax entry </title>
<Style type = "text/CSS">
<! --
Body {
Font-size: 13px;
Background-color: # e7f3ff;
}
FORM {
Padding: 0px; margin: 0px;
}
Input {
Border-bottom: 1px solid # 007eff;/* underline */
Font-family: Arial, Helvetica, sans-serif;
Color: # 007eff;
Background: transparent;
Border-top: none;
Border-left: none;
Border-Right: none;
}
P {
Margin: 0px;
Padding: 2px 2px 2px 10px;
Background: url(icon.gif) No-repeat 0px 10px;/* Add a small icon */
}
-->
</Style>
<Script language = "JavaScript">
VaR XMLHTTP;
Function createxmlhttprequest (){
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}
// Create an XMLHTTPRequest object
Createxmlhttprequest ();
Function callserver (){
// Obtain the data in the form
VaR city = Document. getelementbyid ("city"). value;
VaR state = Document. getelementbyid ("state"). value;
// Return if not specified
If (city = NULL) | (city = "") return;
If (State = NULL) | (State = "") return;
// Link to the server and get the code automatically. In this example, the server is not linked.
VaR url = "getzipcode. php? City = "+ escape (city) +" & State = "+ escape (State );
// Open the link
XMLHTTP. Open ("get", URL, true );
// Tell the server what to do after running (it may take five or five hours). The updatepage function is triggered here.
XMLHTTP. onreadystatechange = updatepage;
// Send the request
XMLHTTP. Send (null );
}
// Process Server Response
Function updatepage (){
If (XMLHTTP. readystate = 4 ){
VaR response = XMLHTTP. responsetext;
Document. getelementbyid ("zipcode"). value = response;
}
}
</SCRIPT>
</Head>
<Body>
<Form>
<P> City: <input type = "text" name = "city" id = "city" size = "25" onchange = "callserver ();"> </P>
<P> country: <input type = "text" name = "state" id = "state" size = "25" onchange = "callserver ();"> </P>
<P> code: <input type = "text" name = "zipcode" id = "city" size = "5"> </P>
</Form>
</Body>
</Html>

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.