JavaScript FAQ (ix)--ajax__ database

Source: Internet
Author: User

Seven, Ajax problems

1. Ajax: Asynchronous JavaScript and XML (ajax:asynchronous JavaScript and XML)

Q: What is the meaning of the popular word ajax?

a: The phrase Ajax was originally proposed by Jesse James Garrett, co-founder of Adaptive Path. Abbreviation Ajax (usually only the first letter a) represents asynchronous JavaScript and XML (asynchronous JavaScript and XML); Essentially, it's a marketing phrase, meaning a set of technologies that can develop a new Web application.

An AJAX-based Web application that differs from the traditional Web site: Features can manage applications on client computers without reloading the Web page, and the widely used Document Object Model (DOM) and JavaScript to perform interactive applications; Relies on XMLHttpRequest calls (or similar techniques) to exchange information with Web servers, and asynchronously performs data exchange between client servers in the background, while users can continue to interact with Web applications in the browser.

Paul Graham gives the following characteristics of an AJAX-based Web application in his article Web 2.0:

Fundamentally, "Ajax" means "JavaScript works." "This means that web-based applications can now do more like desktop programs. When you read this article, a whole new generation of software using AJAX benefits is being written. This is a wave of new applications since the advent of microcomputers.

2. XMLHttpRequest

Q: How can I request data from the server without overloading the page?

A: JavaScript code that has been loaded into the client browser can request additional data from the Web server through the XMLHttpRequest object. Try this:

In this example, when you click the Send request button, the browser requests additional data (file requested_file.html) from the server, and then executes the following code to display the returned data in a message box:

var orequest = new XMLHttpRequest ();
var surl  = "http://" +self.location.hostname+ "/faq/requested_file.htm";
Orequest.open ("Get", surl,false);
Orequest.setrequestheader ("User-agent", navigator.useragent);
Orequest.send (NULL)
if (orequest.status==200) alert (orequest.responsetext);
else alert ("Error executing XMLHttpRequest call!");

In most of today's browsers, the general syntax for Xmlhttprequest.open () is as follows:

var orequest = new XMLHttpRequest ();
Orequest.open (method, URL, async)

The meaning of the parameter method, URL, and async is:

Method Specifies the methods used by the HTTP request, possibly one of the following: ' Get ', ' POST ', ' head '.

The URL specifies the URL that the request is sent when Xmlhttprequest.send () executes.

Async Boolean. If true, HTTP should be executed asynchronously, that is, the code will not be enforced until the request results are returned to the browser.

Note that the Xmlhttprequest.open () method itself does not send requests to the Web server. is actually a request sent by the Xmlhttprequest.send () method.

Also note that in older browsers, such as MicroSoft Internet Explorer 6 or earlier, you may not be able to use the simple method above to initialize Xmlhttprequest:new XMLHttpRequest. Depending on the client configuration, you might want to use one of the following two statements instead:

Orequest = new ActiveXObject ("Msxml2.xmlhttp");
Orequest = new ActiveXObject ("Microsoft.XMLHTTP");
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.