Talking about Ajax request technology _ajax related

Source: Internet
Author: User

1. Written in front:

Read Request:

With certain HTML, CSS, JavaScript, JSON basics

2. What is Ajax

Ajax: "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML) refers to a web development technology that creates interactive Web applications.

3. Why use Ajax

In the Dynamic Web development technology, the client (usually the browser) and the server data interaction is very frequent, how to save network resources, provide a good user experience is very critical. Ajax using asynchronous request, so that without refreshing the entire page can be implemented with the background data interaction, thus updating content ...

4. How to use native Ajax

The key point of using AJAX technology falls on the XMLHttpRequest (note: IE5, IE6 use ActiveXObject) object, so it is critical to make good use of this object

Attention:

    

function LoadData () {//Create XMLHttpRequest object var xmlhttprequestobj = {};

  Creates a JSON object that transmits JSON-formatted data to the server-side Var jsonobj = {}; if (window.

   XMLHttpRequest) {//ie7+, Firefox, Chrome, Opera, Safari xmlhttprequestobj =new XMLHttpRequest ();

   else {//IE6, IE5 xmlhttprequestobj =new activexobject ("Microsoft.XMLHTTP");

     //When the request state changes, the Xmlhttprequestobj. 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 ("Send () function executed, header and status code can get")} else if (xmlhttprequestobj.

    ReadyState = = 3) {Alert ("head received, analytic response body");

        else if (xmlhttprequestobj.readystate = 4) {Alert ("request Complete");

        If (Xmlhttprequestobj.status =) {Alert ("The response is ready, deserializing the JSON object fills the data to the page"); } ELSE if (Xmlhttprequestobj.status = =) {Alert ("page missing");

        else {Alert ("service exception"); //method: Request method: Get, POST, put, DELETE ...

  URL: The requested address ASNYC: whether to use asynchronous Xmlhttprequestobj.open ("method", "url", async); Set the request header, the POST request format needs to be loaded, others do not need Xmlhttprequestobj.setrequestheader ("Content-type", "application/x-www-form-urlencoded

  ");

Request data, parameter is jsonobj JSON object Xmlhttprequestobj.send (jsonobj); }

The above article on the AJAX request technology is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.