Simple Ajax asynchronous Processing

Source: Internet
Author: User
  1   <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >  
2   < Html Xmlns = "Http://www.w3.org/1999/xhtml" >
3   < Head >
4   < Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" />
5   < Title > Untitled document </ Title >
6 < Script Type = "Text/JavaScript" >
7 VaR XMLHTTP;
8 Function Createxmlhttprequest ()
9 {
10 If (Window. activexobject) // Judge the asynchronous object type of the browser;
11 {
12 XMLHTTP = New Activexobject ( " Microsoft. XMLHTTP " ); // Instantiate an asynchronous object;
13 }
14 Else If (Window. XMLHttpRequest)
15 {
16 XMLHTTP = New XMLHttpRequest ();
17 }
18 }
19 Function Startrequest ()
20 {
21 Createxmlhttprequest (); // Call an asynchronous object;
22 XMLHTTP. onreadystatechange = Function () // Response server call method;
23 {
24 If (XMLHTTP. readystate = 4 ) // Determine whether the request is complete
25 {
26 VaR A = XMLHTTP. responsetext; // Obtain the data returned by the server and assign it to variable.
27 Alert ()
28 }
29 }
30 XMLHTTP. Open ( " Get " , " Admin. php " , True ); // Use the get method to access a server-side URL link script and asynchronously process the creation of a server request
31 XMLHTTP. Send ( Null ); // Send a request;
32 }
33 </ Script >
34 </ Head >
35
36 < Body >
37 < Input Type = "Button" Value = "Submit" Onclick = "Startrequest ()" />
38 </ Body >
39 </ Html >
40
41 Admin. php
42 <? PHP
43 Echo "My name is youyou"
44 ?>

 

Summary:

1: Judge the browser and instantiate the XMLHTTPRequest object;

2:CodeSegment;

3: Create a request to access the server scripting language through the open method;

4: Send this request using the send method;

 

 

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.