AJAX in Action

Source: Internet
Author: User

Like everyone else, I was amazed when I saw Ria apps, such as Google Maps and Google suggest. I want to know how it is achieved. Now, the mystery is uncovered, and that is Ajax. This was only known after I spent some time studying Ajax. Here's a good example of how AJAX can be used well in javarss.com.

What is Ajax: AJAX is an architecture (architecture) is not a technology. Ajax represents asynchronous JavaScript and XML.

quip (Punch line): deferred loading

question: When the javarss.com home page loads, he also loads an introduction to all the entries (if you activate them in the settings). These descriptions are displayed only when you move the mouse over the item.

The problem now is that it is not possible for the user to move through all the entries, so preload all the introductions is not a good idea.

solution: using AJAX, the introduction of dynamically loading entries from the server when the mouse is moved.

Doing so will reduce the initial page load size by half or more, so that the page loads faster and can get a better user experience.

Timeline diagram:

We'll first call JavaScript function getdescription in the onmouseover event. Here is the HTML code: Java & EE news java & ee News

 

JavaScript Code:

function GetDescription (channelid,itemid) {

var url = ' http://localhost:8080/getDescription.jsp?channelId= ' + channelid + ' &itemid= ' + itemId;

if (window. XMLHttpRequest) {

req = new XMLHttpRequest ();

else if (window. ActiveXObject) {

req = new ActiveXObject ("Microsoft.XMLHTTP");

}

req.onreadystatechange = ProcessRequest;

Req.open ("Get", url, true);

req.send (null);

}

function ProcessRequest () {

if (req.readystate = = 4) {

if (req.status = =) {

parsemessages ();

} else {

alert ("Not able to retrieve description");

}

}

}

function Parsemessages () {

response = req.responseXML.documentElement;

itemdescription = response.getelementsbytagname (' description ') [0].firstchild.data;

alert (itemdescription);

}

JSP Code:

Resources:


Google sites using Ajax:


   

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.