Knowledge that must be learned before using Ajax _ajax

Source: Internet
Author: User

Full name of Ajax:
Asynchronous JavaScript and XML
(Asynchronous JavaScript and XML)

Ajax is not some kind of programming language
is a technology that can update part of a Web page without reloading the entire page.

A complete HTTP request process, there are 7 steps:
1. Establish a TCP connection.
The 2.Web browser sends a request command to the Web server.
The 3.Web browser sends the request header information.
4.Web server Response.
The 5.WEB server sends the reply header information.
The 6.WEB server sends data to the browser.
7.Web Server shutdown TCP connection

An HTTP request generally consists of four parts:
1.http the requested method or action, such as a GET or POST request.
2. The URL being requested.
3. Request header, including some client environment information, authentication information, etc.
4. The request body, which is the request body, can contain the customer's submitted query string information, the form information, and so on.

Get: (idempotent: is a GET request to execute once and execute 10,000 times is the same effect)
1. Generally used for information acquisition (query),
2. Use URL to pass parameters,
3. The number of messages sent is limited, generally in 2000 characters.
4. The advantage is that you can add to the bookmark Favorites page.

POST:
1. Generally used to modify the resources on the server,
2. There is no limit to the amount of information sent,
3. Is embedded in the HTTP request body.

An HTTP response is usually made up of three parts:
1. A status code consisting of a number and text that shows whether the request was successful or failed,
2. The response head, as well as the request header, contains many useful information, such as service type, date time, content type and length, etc.
3. Response body: The response body

The HTTP status code is composed of 32 digits, where the first digit defines the type of the status code:
1XX: Information class, which indicates that a Web browser request has been received and is being processed further.
2XX: Success, indicating that user requests are properly accepted, understood, and processed, for example:
3XX: Redirect, indicating that the request did not succeed, the customer must take further action,
4XX: Client error, which indicates that there is an error in the client commit request, for example: 404 Not Found, which means that the document referenced in the request does not exist.
5XX: Server error, indicating that the server could not complete processing of the request, for example: 500

Basic concepts of JSON
1.json:javasscript Object Notation, (JavaScript Object notation)
2.json is the syntax for storing and exchanging text information, similar to XML. It uses key-value pairs to organize, easy for people to read, and also easy to machine parsing and generation.
3.json is language-independent, that is, no matter what language you can parse JSON, just follow the rules of JSON.

JSON and XML comparisons
The length of the 1.json is shorter than the XML format.
2.json Read and write faster
3.json can be used in JavaScript in the inner-Jiande method directly to parse, converted to JavaScript objects, very convenient.

JSON can be of the following type:
1. Numbers (integers or floating points), such as 123,1.23.
2. String (in double quotes)
3. Logical value (TRUE or FALSE)
4. Array (in square brackets)
5. Objects (in curly braces)
6.null

Ways to parse JSON:
1.var Jsondata = {"Staff": [{"Name": "Red Flag", "Age": "},{" "Name": "Little Red", "Age": "13"}]};
var jsonbj = Json.parse (Jsondata);
Alert (Jsonbj.staff[0].name)

Using jquery to implement Ajax
1.jquery.ajax ([Settings])
2.type: Type, "POST" or "get", default to "get".
3.url: Sends the requested address.
4.dataType: The data type that is expected to be returned by the server, if not specified, jquery will automatically intelligently judge against the HTTP packet mime information, which we typically use in JSON format and can be set to "JSON".
5.success: is a method that requests a successful callback function, passing in the returned data, and a string containing the successful code.
6.error: is a method that the callback uses when the request fails. Incoming XMLHttpRequest object.

Cross-domain
1. The address of a domain name consists of:
Protocols, subdomains, primary domain names, and any one of the port numbers are different,
2. Requests for resources between different domains are counted as "Cross-domain",
3. such as http://www.abc.com/index.html request http://www.egf.com/service.php
4.jsvsscript for security reasons, do not allow Cross-domain calls to other pages of objects, what is Cross-domain, the simple understanding is because JavaScript is the same as the limitations of the policy, a.com domain name JS can not operate B.Com or c.a.com domain name under the object.
5. For example www.abc.com/index.html call https://www.abc.com/servic.php (Cross-domain)

Methods to handle Cross-domain-agents
1. Create a proxy by using the Web server side of the same domain name
2. Beijing server (domain name: www.beijing.com)
3. Shanghai Server (domain name: www.shanghai.com)
4. For example, the background of the Web server in Beijing (www.beijing)

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.