Ajax Full-Contact Concept Introduction
- Asynchronous:
- Refers to the execution of a program does not block other program execution, which is manifested in the order of execution of the program does not depend on the program itself, but rather synchronous. The advantage is that it does not block the execution of the program, thereby improving overall execution efficiency.
- The approximate process for implementing Asynchrony:
- Use HTML and CSS to implement pages, express information
- Asynchronous exchange of data using XMLHttpRequest and Web servers
- Use JavaScript to manipulate the DOM for dynamic local refreshes.
- http: A rule that enables a computer to communicate over a network.
- is a stateless protocol. That is, do not establish persistent links.
- The process of the HTTP request:
- Establish a TCP connection (TCP: Transmission Control Protocol. A TCP connection is one of the Internet link protocols. Characterized by: orderly and reliable)
- Web browser sends request command to Web server
- Web browser sends request header information
- Web server Answer
- Web server sends answer header information
- Web server sends data to browser
- Web server shuts down TCP connection
- An HTTP request typically consists of four parts:
- The method or action of an HTTP request, such as a GET or POST request
- The URL being requested
- The request header, which contains some client environment information, authentication information, etc.
- The request body, which is the request body. The request body can contain the query string information submitted by the Customer, form information, and so on.
- An HTTP response is typically made up of three parts
- A number and text-based status code to show whether the request succeeded or failed
- Response header: Contains many useful information like the request header, such as server type, datetime, content type, length, and so on.
- Response body: That is, the response body
- The difference between a GET request and a POST request:
- Get: Generally used for information acquisition, using URL to pass parameters, the number of messages sent is also limited, generally in 2000 characters
- POST: Typically used to modify resources on the server, no limit on the number of messages sent
- The HTTP status code has a 3-digit number, with the first number defining the type of the status code:
- 1XX: Information class, which indicates that a Web browser request is being received and is being processed in one step
- 2XX: Success means that user requests are received, understood, and processed correctly. Example: K OK
- 3XX: Redirect to indicate that the request has not been successful and that the customer must be able to move further.
- 4XX: Client error. Indicates that the client submitted a request with an error. For example: 404 Not Found.
- 5XX: Server error, indicating that the server could not complete processing of the request. Example: 500
- XMLHttpRequest Relax Request:
-
Open (method,url,async)
- method: How to request
- URL: Requested address (relative or absolute)
- Async: Asynchronous (Async: TRUE), the default value is true.
-
Send (String)
. The requested content.
- If a GET request is send (null)
- If it is a POST request or send (content), the contents are used & spliced
- if it is a POST request, also request header
setRequestHeader (' Content-type ', ' application/x-www-form-urlencoded ')
- XMLHttpRequest Get a response
responseText
: Get response data in string form
responseXML
: Get response data in XML form
status和statusText
: Returns the HTTP status code in numeric and textual form.
getALLResponseHeader()
: Get all the response headers
getResponseHeadr()
: The value of a field in a query response
readyState
Property:
- 0: Request uninitialized, Open has not been called
- 1: The server connection has been established and open has been called
- 2: The request has been received, that is to receive the header information
- 3: The request is processed, that is, the response body is received
- 4: The request is complete and the response is ready, that is, the response is complete.
- Can be used to
onreadystatechange
listen readyState
for changes in values.
- PHP General Introduction:
- PHP is a server-side scripting language that creates dynamic interactive sites.
- # # # #php的大致功能:
- Ability to generate dynamic page content.
- Ability to create, open, read, write, delete, and close files on the server
- Ability to receive form data
- Ability to send and retrieve cookies
- Ability to add, delete, and modify data in a database
- Ability to restrict access to certain pages in the site.
- The basic server language can do all you can.
- Json:
- JavaScript objects notation (JavaScript object Notation)
- JSON is the syntax for storing and exchanging textual information, similar to XML. He is organized by key-value pairs, easy for people to read and write, and easy to machine parse and generate
- JSON is language-independent, meaning that JSON can be parsed in any language, simply by following the rules of the JSON.
- The advantages of JSON versus XML
-
- The length of the JSON is shorter than the XML format.
- JSON reads and writes more quickly
- JSON can be parsed using JavaScript built-in methods and converted to JavaScript objects, which is very handy.
- JSON syntax rules
-
- The writing format for JSON data is: name/value pairs. Note that the data must be enclosed in double quotation marks.
- The JSON values can be the following types
-
- Number (integer OR)
- String (in double quotes)
- Logical value (TRUE or FALSE)
- Array (in square brackets)
- Object (in curly braces)
- Null
-
- Implementing Ajax with jquery:
-
- Syntax: Jquery.ajax ([Settings])
- Type: ' POST ' or ' get ', default ' get '
- URL: Sending the requested address
- Data: Is an object that is sent to the server, along with the request.
- DataType: Expected data type returned by the server. If not specified, jquery will automatically be based on the HTTP packet MIME information to intelligently judge, generally we use the JSON format, can be set to ' JSON '
- Success: is a method that requests a successful callback function. The data after the incoming return, and the string containing the success code
- Error: is a method that calls this function when a request fails. Incoming XMLHttpRequest Object
- Cross-domain:
-
- The composition of a domain name address:/http/www. Abc.com:8080/scripts/jquery.js
- (protocol) (subdomain) (primary domain name) (port number) (Request resource address)
- When any of the protocols, subdomains, primary domain names, or port numbers are different, they are counted as distinct domains
- Different domains request resources from each other, even if you do ' cross-domain '. For example: http://www.abc.com/index.html request http://www.efg.com/service.php
- JavaScript is not allowed to invoke objects of other pages across domains for security reasons. What is the cross-domain, simple understanding is because of the JavaScript homologous policy limitations, a.com domain name JS can not operate B.Com or c.a.com the object under the domain name.
- Note: There can be many subdomains under a primary domain name.
- Ways to handle cross-domain:
-
- Proxy: Create a proxy by using the Web server side of the same domain name.
-
- Beijing server (domain name: www.beijing.com) damage Server (domain name: www.shanghai.com)
- For example, in Beijing's Web server Backstage (www.beijing.com/proxy-shanghaiservice.php) to call the Shanghai server (www.shanghai.com/ service.php) service, and then return the response results to the front end, so that the front-end calls to Beijing with the domain name service is the same as the call to Shanghai service effect.
- JSONP: A problem that can be used to troubleshoot cross-domain data access for mainstream browsers.
-
<script>function Jsonp (JSON) {alert (json[' name ']);} </script><script src = ' http://www.bbb.com/jsonp.js ' ></script> jsonp in www.bbb.com page ({' name ': ' Hung Seven ') , ' Age ': 24});
-
-
-
- Only get requests. Unable to process the POST request.
- PostMessage solve cross-domain??????
- Cros
-
- XHR2
-
- The XMLHttpRequest Level2 provided by HTML5 has implemented cross-domain access and a number of other new features
- IE10 versions are not supported.
- On the server side to do some small transformation can:
-
- Header (' access-control-allow-origin:* ');
- Header (' Access-control-allow-methods:post,get ');
Ajax Full Contact