About ajax request technology and about ajax requests

Source: Internet
Author: User

About ajax request technology and about ajax requests

1. Preface:

Reading requirements:

Basic HTML, CSS, JavaScript, and Json

2. What Is ajax?

Ajax: "Asynchronous Javascript And XML" (Asynchronous JavaScript And XML) is a web page development technology used to create interactive web applications.

3. Why ajax?

In dynamic web development technology, data interaction between the client (usually a browser) and the server is very frequent. It is critical to save network resources and provide a good user experience. Ajax adopts the asynchronous request method, so that data interaction with the background can be implemented without refreshing the entire page, so as to update the content...

4. How to use native ajax

The key point of ajax technology lies in the XMLHttpRequest (Note: ie5 and ie6 use ActiveXObject) object. Therefore, it is critical to make good use of this object.

Note:

    

Function loadData () {// create the XMLHttpRequest object var xmlHttpRequestObj ={}; // create a json object and transmit the json format data to the server Var jsonObj ={}; if (window. XMLHttpRequest) {// IE7 +, Firefox, Chrome, Opera, Safari xmlHttpRequestObj = new XMLHttpRequest ();} else {// IE6, IE5 xmlHttpRequestObj = new ActiveXObject ("Microsoft. XMLHTTP ");} // xmlHttpRequestObj is called when the Request status changes. onreadystatechange method xmlHttpRequestObj. onreadystatechange = function () {if (xmlHttpRequestObj. readyState = 0) {Alert ("open () function not executed");} else if (xmlHttpRequestObj. readyState = 1) {Alert ("open () function executed, send () function not executed");} else if (xmlHttpRequestObj. readyState = 2) {Alert (the "send () function has been executed, and the header and status code can be obtained")} else if (xmlHttpRequestObj. readyState = 3) {Alert ("the header has been received and the response body is parsed");} else if (xmlHttpRequestObj. readyState = 4) {Alert ("request completed"); If (xmlHttpRequestObj. status = 200) {Alert ("the response is ready, deserialization json object fills in data to the page");} else if (xmlHttpRequestObj. status = 400) {Alert ("Page loss");} else {Alert ("service exception") ;}}// method: Request method: GET, POST, PUT, DELETE... url: requested address asnyc: whether asynchronous xmlHttpRequestObj is used. open ("method", "url", async); // sets the request header. the post request format needs to be loaded, and xmlHttpRequestObj is not required for other requests. setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); // request data. The parameter is the jsonObj json object xmlHttpRequestObj. send (jsonObj );}

The above discussion about the ajax request technology is a small part of the Content shared to everyone, I hope to give you a reference, but also hope you can support the house of helping customers.

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.