Ajax sends and receives requests. Ajax sends and receives requests.

Source: Internet
Author: User

Ajax sends and receives requests. Ajax sends and receives requests.

First, Ajax is widely used to submit data without refreshing new pages !!

Basically, Ajax can receive the information that the browser can receive. ex: String, html Tag, css Tag, xml format content, json format content, and so on .....

<Script> // IE browser if (ActiveXObject) {// the latest version of Microsoft AJAX var ajax = new ActiveXObject ("Msxm12.XMLHTTP. 6.0 ");} else {// mainstream browser var ajax = new XMLHttpRequest ();} // create an HTTP request // open (method, url, asynchronous, user, password ); // method: Request method (post, get) // url: request address (the address of the specific data to be received) // asynchronous: synchronous or asynchronous request (true is asynchronous, "false" indicates synchronization. The default value is "true". You can leave it empty. // user :( specify the request username, but do not enter it) // password :( specify the request password, or leave it empty) ajax. open ('get', 'url'); ajax. onreadystatechange = function () {if (ajax. readyState = 4) & (ajax. status) = 200) {alert (ajax. responseText); // returned data content} else {alert ('request failed');} // send the request. The content is the content to be sent, if not, enter null send (content); // If a post request is used, set the HTTP header ajax before sending. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); </script>

The onreadystatechange event of ajax can receive up to four changed states.

Returned status value of readystate:

0 (not initialized) the object has been created

1 (initialization) The open method has been called

2 (send data) The send method has been called

3 (in data transmission) Some data has been returned

4. The request is completed successfully.

The above is a simple Ajax request principle and I hope it will be helpful for your learning.

Articles you may be interested in:
  • How to process XMLHttpRequest objects that send multiple requests simultaneously in AJAX
  • The post method parameter sending Method for Extjs ajax synchronous requests
  • Jquery + ajax sends request data to the background every second and then returns the code of the page
  • How to Implement ajax delayed sending to send ajax requests after idle
  • Example of jquery cross-origin request sharing (jquery sends ajax requests)
  • Jquery ajax asynchronous request receiving returns a json data instance
  • Jsp + ajax Method for sending GET requests
  • How js and jQuery terminate an ajax request being sent
  • Solution to prevent repeated Ajax requests

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.