Asynchronous ajax
Related Tags:
In the village often see someone asked xajax technology, telling the truth, I think that things too much trouble, too cumbersome to use.
Ajax mechanism itself is not difficult to achieve, it is difficult to be dealt with in the latter part of the return of javascript responseText, responseXml
Ajax the operation of the process itself without outside is:
1. Like to build a xmlHTTP
2. XmlHTTP through synchronous or asynchronous send data (mostly asynchronous mode)
3. Asynchronous mode check if the state changes xmlHttp
4. When the state variable to the readyState == 4, and the status == 200 successfully sent data
5. This point in time through the responseText xmlHTTP handling javascript or responseXml (these two are there at the same time)
Below this process to achieve
1. Build on as a xmlHTTP
CODE: function createRequest () (
If (typeof XMLHttpRequest! = "Undefined") (
Return new XMLHttpRequest ();
) Else if (typeof ActiveXObject! = "Undefined") (
Var xmlHttp_ver = false;
Var xmlHttp_vers = [ "MSXML2.XmlHttp.5.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp", "Microsoft.XmlHttp"];
If (! XmlHttp_ver) (
For (var i = 0; i <xmlHttp_vers.length; i + +) (
Try (
New ActiveXObject (xmlHttp_vers [i]);
XmlHttp_vers xmlHttp_ver = [i];
Break;
) Catch (oError) (;)
)
)
If (xmlHttp_ver) (
Return new ActiveXObject (xmlHttp_ver);
Else ()
Throw new Error ( "Could not create XML HTTP Request.");
)
Else ()
Throw new Error ( "Your browser doesn't support an XML HTTP Request.");
)
) NOTE: xmlHttp_vers should version to version of the high-low writing, such as the establishment of the data transfer is installed on your machine had the highest version of the MSXML2.XmlHttp
The second step is sending the data here call xmlHttp the open method and send methods to deal with
XmlHTTP method can be to www.xmlhttp.cn Show (I had previously issued a chm, but because copyright was mayor delete you, whoever wants to, the letter to me)
Below is the method by post send data
CODE: var xmlHttp;
XmlHttp = createRequest ();
Function sendPostRequest ()
(
Var shownum = document.getElementById ( "shownum"). Value; / / html page shownum id as a form of input
Var url = "show.php" / / should be sent to the URL
Var queryString = "shownum" + "=" + shownum;
/ / Send the request to the server
XmlHttp.open ( "post", url, true); / / here for the third parameter to true asynchronous processing
XmlHttp.onreadystatechange = showData; / / asynchronous processing, when the status change will be called onreadystatechange attributes specified callback function showData
XmlHttp. SetRequestHeader ( "Content-Type", "application / x-www-form-urlencoded ;");// This is a method sent by post must be written in the time
XmlHttp.send (queryString); / / Send your building 10% of the data, if the "get" method, can be written here xmlHttp.send (NULL);
The third step)
When the state changes will be called onreadystatechange property designated showData callback function to check the state changes
XmlHTTP.readyState xmlHTTP.status can to investigate and manual, look at the know
CODE: function showData ()
(
Var msg = document.getElementById ( "status");
/ / Step 4
If (xmlHttp.readyState == 4)
(
If (xmlHttp.status == 200)
(
/ / Only when the readyState status for the 200 and 4 when they said that to meet the requirements
/ / Below this sentence, said that the equivalent of the above five steps to deal with the return of results
Msg.innerHTML = xmlHttp.responseText;
)
)
Else
(
Switch (xmlHttp.readyState)
(
Case 0:
Msg.innerHTML = "Uninitialized ...";
Break;
Case 1:
Msg.innerHTML = "Loading ...";
Break;
Case 2:
Msg.innerHTML = "link completed ...";
Break;
Case 3:
Msg.innerHTML = "exchange of data ...";
Break;
Default:
Break;
)
)
) Here to send a xmlhttp pace with asynchronous transfer data even if you complete integrity of the code is
CODE: <html>
<head>
<title>
Ajax
</ Title>
<script Language="javascript">
Function createRequest () (
If (typeof XMLHttpRequest! = "Undefined") (
Return new XMLHttpRequest ();
) Else if (typeof ActiveXObject! = "Undefined") (
Var xmlHttp_ver = false;
Var xmlHttp_vers = [ "MSXML2.XmlHttp.5.0", "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp", "Microsoft.XmlHttp"];
If (! XmlHttp_ver) (
For (var i = 0; i <xmlHttp_vers.length; i + +) (
Try (
New ActiveXObject (xmlHttp_vers [i]);
XmlHttp_vers xmlHttp_ver = [i];
Break;
) Catch (oError) (;)
)
)
If (xmlHttp_ver) (
Return new ActiveXObject (xmlHttp_ver);
Else ()
Throw new Error ( "Could not create XML HTTP Request.");
)
Else ()
Throw new Error ( "Your browser doesn't support an XML HTTP Request.");
)
)
Var xmlHttp;
Function sendPostRequest ()
(
XmlHttp = createRequest ();
Var shownum = document.getElementById ( "shownum"). Value; / / html page shownum id as a form of input
Var url = "show.php" / / should be sent to the URL
Var queryString = "shownum" + "=" + shownum;
/ / Send the request to the server
XmlHttp.open ( "post", url, true); / / here for the third parameter to true asynchronous processing
XmlHttp.onreadystatechange = showData; / / asynchronous processing, when the status change will be called onreadystatechange attributes specified callback function showData
XmlHttp. SetRequestHeader ( "Content-Type", "application / x-www-form-urlencoded ;");// This is a method sent by post must be written in the time
XmlHttp.send (queryString); / / Send your building 10% of the data, if the "get" method, can be written here xmlHttp.send (NULL);
)
Function showData ()
(
Var msg = document.getElementById ( "status");
/ / Step 4
If (xmlHttp.readyState == 4)
(
If (xmlHttp.status == 200)
(
/ / Only when the readyState status for the 200 and 4 when they said that to meet the requirements
/ / Below this sentence, said that the equivalent of the above five steps to deal with the return of results
Msg.innerHTML = xmlHttp.responseText;
)
)
Else
(
Switch (xmlHttp.readyState)
(
Case 0:
Msg.innerHTML = "Uninitialized ...";
Break;
Case 1:
Msg.innerHTML = "Loading ...";
Break;
Case 2:
Msg.innerHTML = "link completed ...";
Break;
Case 3:
Msg.innerHTML = "exchange of data ...";
Break;
Default:
Break;
)
)
)
</ Script>
</ Head>
<body>
<div> To send data: <input name = "shownum" id = "shownum" type = "text"> <input type = "button" name = "search" value = "send" onClick = "sendPostRequest ()" > </ div>
<div Id="status"> </ div>
</ Body>
</ Html> the same directory to have a show.php
Says
CODE: <? Php
$ Shownum = $ _POST [ "shownum"];
Echo $ shownum;
-->
- AJAX Technology
- AJAX
- What is AJAX
- Ajax --
- Asynchronous JavaScript and Ajax request issued
- Acquaint AJAX
- ? Asynchronous JavaScript and XML (AJAX) with Java 2 Enterprise Edition
- About AJAX
- The Ajax
- Wrote the AJAX
- Ajax bad
- Ajax is not mysterious
- AJaX for weblogs
- Asynchronous callback (pseudo-Ajax mode)
- What is Ajax?
- Thinking in AJAX (1) - AJAX
- AJAX browser
- Asynchronous ajax
- AJAX, tasteless!
- Ajax resources or Ajax Resources
- Ajax Profile
- AJAX Essentials
- Pragmatic Ajax
- About''Ajax '
How to achieve iframe (embedded frame) highly adaptive

The question was asked several times to see how to achieve iframe asked Adaptive height, as can the length of pages automatically adapt to remove pages and iframe at the same time rolling of the phenomenon, I just work and have encountered similar problems, So check the Internet, look at the...
Database operation with Dreamweaver

Some time, we often need to customer information and other information posted to the Internet to contact, but with the growing number of customer information, online updates are increasingly insufficient, and this how? In fact, apart from using asp, php language such as backgrou...
Flash Actionscript the implementation of the order scripts

Flash done a script about the status of the implementation of the order tests and summarize here the following rules: 1. Frame to the implementation of the script, then the implementation of the frame in the video clip frame script. 2. Different layers in the same ...
Fireworks MX examples of mixed layer analysis

Layer graphics processing is the most fundamental concept, but I found many of my friends for Fireworks MX layers mixed mode does not seem to be very understanding, in fact if properly used the mixed layer, the effect of reach of many complex. Do not believe that? Th...
The Flash ActionScript a classroom Record

First stresses Who Where How Good morning, first of all, thank you in the sweltering heat and join me in learning AS! Because the weather is too hot, as far as possible, to streamline the contents of lectures, this is the first lesson, I used the three English word...