1,Ajax(Asynchronous JavaScript and XML) that is, Asynchronous JavaScript and XML
2. synchronous/asynchronous differences
Synchronization: ① Refresh the entire page each time. ② the synchronization link can only have one link at a time, and its operation will prevent the running of xingxu Js, JS must continue to run after the synchronization link is completed.Asynchronous: ① Only refresh the part to be updated each time. ② multiple parts can occur. At the same time, JS execution will not be blocked. |
3. features and advantages of asynchronous loading/ajax
① Partial refresh and load as needed. Only some truly changed parts of the page are updated; ② It can reduce the data traffic of the server. The page is updated, and the user can continue to work. ③ The browser can request multiple contents from the server at the same time. ④ The traffic transmitted each time is relatively small than the response, and the browser requests return faster |
4. Why cannot I apply for Data Using ajax on the entire page?
Because it is not conducive to Seo, the tag is empty inside and Seo cannot be captured. For information that is more important than the keyword on the page, static |
5. Several Basic Ajax APIs
① New XMLHttpRequest ()(Ie5 and IE6 use activexobject ). ② Open () ③ Send () ④ Onload () ⑤ Responsetext () |
Internet Explorer (ie5 and IE6) of earlier versions use ActiveX objects:variable=new ActiveXObject("Microsoft.XMLHTTP"); To handle all modern browsers, including ie5 and IE6, check whether the browser supports XMLHttpRequest objects. If yes, create an XMLHTTPRequest object. If not, activexobject is created: var xmlhttp;if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } |
Open (method, URL, Asyn) determine the URL and method to be linked Number of requests method: String scheme request URL: string in the form of post/get, URL to be linked Asyn: Boolean, whether to initiateAsynchronousRequest |
Send (data) Number of shards |
?
6. basic steps of asynchronous loading
<SCRIPT> VaR url = '2.html '; // Create a request VaR xhr = new XMLHttpRequest (); // Determine the Request Method and request address Xhr. Open ('post', URL, true ); // Request Xhr. Send (null ); // Server end load complete Xhr. onload = function () {document. writeln (xhr. responsetext );} </SCRIPT> |
7,
AJAX can only process text files and cannot process images.8. script code in innerhtml will not be run, and Ajax returns a string
The role of eval: Run the string as Js. If the Js in innerhtml is not running, the eval method must be used. However, the performance is poor, at the same time, there are differences between the strict mode and the non-strict mode of JS, and as few items as possible in the project and code. Xhr.Onload= Function (){ Con. innerhtml = xhr. responsetext;/* script under con */ VaR cons = con. getelementsbytagname ('script '); For (VAR I = 0; I <cons. length; I ++ ){ Eval(Cons [I]. innerhtml ); }; } |
/* * A. Add a value directly after the object data. Add a property; * B. Use the [] method to retrieve tokens. It is a bit similar to an array, but it is indexed by key; */ VaR JSON = '{"A": "HTML5 freetier", "B": "Huang Yibin "}'; VaR DATA = eval ("(" + JSON + ")"); Alert (data. A); // pop-up: HTML5 freetier Alert (data ['B']); // pop-up: Huang Yibin |
Assume that each tab switch uses a text format to create a large number of tabs. At this time, the data format JSON or XML is required.
9 ,? Data formatJSON and XML are common data formats.
JSON (JavaScript Object Notation) Lightweight data format. The literal translation is JavaScript Object symbol. XML is an extensible markup language, and both HTML and HTML are Markup languages. |
10 ,?
Advantages and disadvantages of JSON:
Advantages of JSON |
Disadvantage of JSON |
① Light weight, small size, saving traffic and Improving Loading Speed ② Parse it into a native JS object, and parse it faster than XML ③ Search for data without tags, faster |
In old browsers suchIE7-Native JSON Parsing is not supported. Third-party libraries must be introduced. |
JSON/XML analysis:
①Readability: Both of them are very readable. XML data strictly follows the xml dom model specification, and JSON strictly follows the JS language syntax. ②Scalability: XML data can design more complex data nesting structures by defining tags, while JSON can simulate arbitrary XML data structures through infinite combinations of arrays and objects. ③Encoding difficulty: XML has a variety of coding tools (such as dom4j and JDOM), and JSON also provides tools provided by json.org. However, JSON encoding is much better than xmleasy, and JSON code can be handwritten even without tools, however, it is very difficult to write XML documents manually. ④Decoding difficulty: XML data parsing requires consideration of structural layers and node relationships, which is difficult to parse and does not involve parsing of JSON data. ⑤File Size: For the same data, the XML file size is greater than the JSON file size. |
11. Common JSON format:Objects and Arrays
JSON array Syntax: An array is a set of ordered values.
|
JSON object Syntax: An object is a set of unordered "name/value" pairs.
|
12. JSON data content
JSON data content is represented by values: String, value, logical value, null, object, array
* The string must be enclosed by double quotes. * The value can be directly referenced and does not need to be added? Introduction * The logical values include true and false, which are directly referenced and do not need to be added? Introduction * In JSON data, separators (spaces, tabs, and line breaks) are not parsed, so you can add them anywhere? Blank |
13. JSON data type conversion
JSON.Parse (String);Converts a JSON string to a JSON object.Stringify (OBJ)Converts a JS object to a JSON string. |
Reprinted please indicate the source:
Csdn blog-HTML5 freelancer http://blog.csdn.net/html5 _
What are the basic Ajax knowledge points?