Home > front end >  Asynchronous Ajax JavaScript
Asynchronous Ajax JavaScript

Time:09-20

Knowledge:
1, the JSON: JavaScript Object expression hair (JavaScript Object Notation)
JSON is stored and the exchange of text information syntax:
1) text of JSON is a lightweight data interchange format
2) JSON is independent of the language and platform
3) JSON has self descriptive, easier to understand,
Similar to XML, than XML smaller, faster, easier to parse
(XML: refers to the extensible markup language, XML is designed to transport and store data,)
2, JSON syntax
JSON grammar is a JavaScript object represents a subset of the
1) data in name/value pairs (data) in the key/value pair
2) data has a comma
3) braces save object ({})
4) brackets save array ([])
JSON values can be:
1) number (integer or floating point)
(2) strings in double quotes)
3) Boolean value (true or false)
4) the object (in curly braces)
5) null
3, a JSON object
A JSON object with JS object where there are two different
No variable declarations of variables (1) no JSON concept)
2) no semicolon at the end (because this is not a JavaScript statement, so don't need a semicolon)

4, a JSON array (written in brackets, the array can contain multiple objects)
Combine arrays and objects, can constitute a more complex data collection

5, parsing and serialization
JSON object has two methods:
Stringify () : the JS object serialization for JSON string

The parse () [p ɑ : z] : parsing JSON string for native JS value
The
6, Ajax introduction: not a programming language, is a under the condition of without reloading the whole page, to be able to update the department
Web technology, the traditional web page (do not use the AJAX) if need to update the content, necessary reloading the whole web page, there are a lot of using AJAX application case: sina weibo, Google maps, etc.
7, synchronous and asynchronous
Synchronous: refers to a process at the time of execution of a request, if the request requires some time to return information,
So the process will wait until the return information received to continue execution;
Synchronous:
Request a 1 ms
Request 2 1 ms
Request three 1 ms
Asynchronous 1.3 ms
Asynchronous: refers to the process does not need to wait forever, but continue to perform the following operations, regardless of the other processes,
When there is a message returns system will inform process for processing, so that we can improve the efficiency of execution,
Asynchronous implementation:
1, using HTML and CSS pages, express information
2, using the XMLHttpRequest and web server for the exchange of asynchronous data
3, use JavaScript DOM operation, realize the dynamic local refresh
8, Ajax - create the XMLHttpRequest object
The XMLHttpRequest object: used to exchange data with the server in the background (specific introduce visible w3c)
Create the XMLHttpRequest object: all modern browsers (ie 7 +, Firefox, Chrome, Safari, and Opera) have built-in XMLHttpRequest object,
Create the XMLHttpRequest object syntax:
The
Older versions of Internet Explorer (ie 5 and 6) using the ActiveXObject object:
The
In response to all modern browsers, including IE5 and IE6, please check whether the browser supports the XMLHttpRequest object. If the support, create the XMLHttpRequest object, if it does not support creating ActiveXObject
8, Ajax - sends a request to the server
Sends a request to the server, we use the XMLHttpRequest object open () and send () method:
Open (method, url, asyns) regulation of the type of request, a url and whether the asynchronous request is processed,
Parameter description:
Method: the type of request; GET or POST
Url: the location of the file on the server
Async: true (Asynchronous) or false (synchronous) Asynchronous
Send (string) : sends a request to the server
Parameters: the string is used only for POST request
9, Ajax - server response: using the XMLHttpRequest object responseText or responseXML property get responses from the server
The responseText: string form of the response data obtained,
ResponseXML: XML response in the form of data obtained,
10, Ajax -- the onreadystatechange event:
Every time the readyState changes, will trigger the onreadystatechange event,
Three important properties of the XMLHttpRequest object:
1), onreadystatechange: storage function (or functions), every time the readyState attribute changes, can call this function,
2), the readyState: entities XMLHttpRequest, change from 0 to 4,
0: request uninitialized
1: the server connection has been established
2: the request has been received
3:
in the request processing4: the request has been completed, and the response is ready
3), the status: 200: "OK" 404: a page not found
When the readyState is 4 and the status of 200, said the response ready
The

  • Related