Ajax Knowledge points

Source: Internet
Author: User

Tag: Hang style does not respond ... als amp handles display updates

Ajax is "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML) AJAX is not a programming language, but a technique to update parts of a Web page without reloading the entire page. (implementing local Update data) XMLHttpRequest object creationvarRequest =NewXMLHttpRequest: How to create a workaround for compatibility;varrequest;if(Widsow. XMLHttpRequest) {Request=NewXMLHttpRequest ();//Ie7+,firefox,chrome,oprea,safari .....}Else{Request=NewActiveXObject ("Microsoft.XMLHTTP");//ie6,ie5}

The HTTP request process typically has 7 steps:1, establish a TCP connection (general HTTP is going to be a TCP connection)2, the Web browser sends a request command to the Web server3, the Web browser sends the request header information4, Web server answer5, the Web server sends the answer header information6, the Web server sends data to the browser7, the Web server closes the TCP connection first is the requested part, and the HTTP request is generally divided into 4 parts:1, the method or action of the HTTP request, such as a GET or POST request2, the URL being requested, must know what the requested address is .3, request header information, including some client environment information, authentication information, etc.4, the request body, which is the request body, the request body can contain the query string information submitted by the Customer, form information, etc.*There is a blank line between the general request header and the request body, and this empty line is important to indicate that the request header has ended.

Get: (the method of the default HTTP request) is generally used for information retrieval, it is to use the URL on the page to pass parameters, will be displayed directly after the URL of the Web page, it is the amount of information sent, it is generally 2K capacity (commonly used for query, get operations, visible to anyone, Not high security) POST: Typically used to modify the service's crying resources; it has no limit on the amount of information sent. (often used to send form data, add, modify, etc., not visible to others, high security)
Legend of the request:




followed by the part of the response, an HTTP response typically consists of 3 parts:1, a number and a text-based status code to show whether the request succeeded or failed2, the response header, and the request header contain many useful information, such as server type, datetime, content type, length, and so on3, response body, which is the response body, the response body is generally similar to the request body, and the response body is displayed after a blank line behind the response header.


Legend of Response: (There is no response body in this figure)

XMLHttpRequest Send request: Open (Method,url,Async): Through which you can invoke HTTP request method: Indicates whether a request is sent using the Get method or the Post method, uppercase lowercase can be used, generally uppercase. URL: The URL that represents the sending request (essential), either a relative or an absolute pathAsync: Indicates whether it is synchronous or asynchronous with a value oftrueTable asynchronously, with a value offalseTable Synchronization method (the default value istrue, usually not filled out) send (string): Send the request to the server with a value of get is not writable or null; A value of post is required to fill in the content, otherwise the meaning is not very useful example: Request.open ("GET","get.php",true); Request.send (); Request.open ("POST","post.php".true); send (); Request.open ("POST","create.php".true); Request.setrequestheader ("Content-type","application/x-www-form-urlencoded");//setRequestHeader must be written between open and send, otherwise an exception will be thrown//If you send a file, it is generally used in this wayRequest.send ("name= Zhang San &sex= male");--------------------------------------------------------------------------------XMLHttpRequest Get response: Gets the properties and methods of the response value:1, ResponseText: Getting response data in string form2, Responsexml: Obtaining response data in XML form3, status, and StatusText: Returns the HTTP status code as a number and text form4, Getallresponseheader (): Gets all the response headers5, getResponseHeader (): The value of a field in a query response ReadyState (returns the state of the response) ReadyState the state of XMLHttpRequest. From0To4changed. 0: The request was not initialized, and open has not yet been called1: The server connection has been established and open has been called2: The request has been received, that is to receive the header information3: In request processing, that is, the response body is received4: The request is complete and the response is ready, that is, the response completes an example of the HTTP request process:varRequest =NewXMLHttpRequest (); Request.open ("GET","get.php".true); Request.send (); Request.onreadystatechange=funcgion () {if(Request.readystate = = =4&& Request.status = = = $){//ReadyState = = 4 is used to determine if the response is successful status = = = 200 to determine whether the request succeeded//do some things request.responsetext}  }

Ajax Knowledge points

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.