Traditional web pages do not use Ajax technology. When updating the content of the web page, the page needs to be reloaded to rewrite the page. If it is the entire website, the workload is undoubtedly huge, but with Ajax technology, we add the form design in the background. Related code, asynchronous input and output, local update, which makes the work easier. For example, many well-known websites, such as Tencent, Sina, Google, Baidu Maps, etc., all use this technology.
To learn Ajax technology, it is enough to have the basics of HTML, CSS, and JS.
Traditional synchronous loading is crazy because one object is missing, and that is the XMLHttpRequest object. With this object, the data exchange between the background and the server can be realized, and the partial request and refresh of the page can be achieved. This is the asynchronous function of Ajax.
What we need to do to achieve this functionality is:
1: Use HTML and CSS to write pages to express information.
2: Asynchronous exchange of data with XMLHttpRequest and Web server.
3: Use javascript to operate the DOM to achieve dynamic local refresh.
The important thing is the second point, how to create an XMLHttpRequest object?
It's the following sentence:
var request=new XMLHttpRequest();
But IE5 and IE6 are not compatible.
So write it like this:
var request;
If(window.XMLHttpRequest){
request=new XMLHttpRequest();
}else{
request=new ActiveXObject(“Microsoft.XMLHTTP”);//IE6,IE5
}
That is, if there is a definition of XMLHttpRequest, use it directly, if not, create an ActiveXObject object and use it.
The Ajax flow is like this:
1. Get the required data from the web form.
2. Establish the URL to connect to.
3. Open a connection to the server.
4. Set the function to be run by the server after completion.
5. Send the request.