Ec (2); [AJAX Introduction] Ajax is a Web application development method that uses client scripts to exchange data with Web servers. Web pages can be dynamically updated without interrupting the interaction process and cutting them again. With Ajax, users can create direct, highly available, richer, and more dynamic Web user interfaces close to local desktop applications. Asynchronous merge Cr merge pt and XML (AJAX) are not new technologies. Instead, they use several existing technologies & mdash; including Cascading Style Sheets (script ec (2 ); script
[AJAX Introduction]
Ajax is a Web application development method that uses client scripts to exchange data with Web servers. Web pages can be dynamically updated without interrupting the interaction process and cutting them again. With Ajax, users can create direct, highly available, richer, and more dynamic Web user interfaces close to local desktop applications.
Asynchronous Cr ī pt and XML (AJAX) are not new technologies, but they use several existing technologies-including Cascading Style Sheets (CSS), Javascr ī pt, XHTML, XML, and extensible style language conversion (XSLT), develop Web application software that looks and operates similar to desktop software.
[AJAX execution principle]
An Ajax interaction starts from an object called XMLHttpRequest's Javascr into pt. As the name implies, it allows a client script to execute an HTTP request and parse a server response in XML format. The first step in Ajax processing is to create an XMLHttpRequest instance. Use the HTTP method (GET or POST) to process the request and set the target URL to the XMLHttpRequest object.
When you send an HTTP request, you do not want the browser to suspend and wait for the response from the server. Instead, you want to continue responding to user interface interactions through the page, and post-processing them after the server response actually arrives. To complete this, you can register a callback function with XMLHttpRequest and asynchronously dispatch the XMLHttpRequest request. The Control Right is immediately returned to the browser. When the server responds, the callback function will be called.
[AJAX application]
1. initialize Ajax
Ajax actually calls the XMLHttpRequest object. First, we must call this object. We construct an Ajax initialization function:
/**
* Initialize an xmlhttp object
*/
Function InitAjax ()
{
Var ajax = false;
Try {
Ajax = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Ajax = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (E ){
Ajax = false;
}
}
If (! Ajax & typeof XMLHttpRequest! = ''Undefined ''){
Ajax = new XMLHttpRequest ();
}
Return ajax;
}
You may say that because the XMLHTTP component is called by the IE browser, this code can be used only by Firefox.
Before executing any Ajax operation, we must call our InitAjax () function to instantiate an Ajax object.
2. Use the Get Method
Now let's first execute a Get request. Do we need to Get/show. php? Id = 1 data, so what should we do?
Suppose there is a link: News 1. When I click this link, I don't want to refresh it to see the link content. What should we do?
// Change the link:
News 1
// Set a layer for receiving news, and set it to not display:
At the same time, construct the corresponding Javascr ī pt function:
Function getNews (newsID)
{
// If newsID is not passed in
If (typeof (newsID) = ''undefined '')
{
Return false;
}
// URL for Ajax
Var url = "/show. php? Id = "+ newsID;
// Obtain the position of the news display Layer
Var show = document. getElementById ("show_news ");
// Instantiate an Ajax object
Var ajax = InitAjax ();
// Get requests
Ajax. open ("GET", url, true );
// Obtain the execution status
Ajax. onreadystatechange = function (){
// If the execution is normal,
<