The key knowledge (sharing) _ajax that must be mastered in AJAX applications is related

Source: Internet
Author: User

What is Ajax?

is the acronym for asynchronous Javascript and XML, which is not a new language, but a comprehensive utilization of existing technologies. Its essence is to communicate with the server asynchronously on the basis of HTTP protocol.

The concept of asynchrony?

The execution of a program does not block the execution of other programs, the manifestation of which is that the sequence of execution of the program does not depend on the writing order of the program itself, but instead for synchronization.

The role of Asynchrony?

The advantage is that the execution of the program is not blocked, thus improving the overall execution efficiency.

The core of Ajax?

XMLHttpRequest, abbreviated Xhr,xml Extensible Markup Language, HTTP Hypertext Transfer Protocol, request requests. The XMLHttpRequest object can implement a local update Web page without submitting the entire page to the server. The XMLHttpRequest object provides full access to the HTTP protocol, including the ability to make POST and head requests and normal get requests. XMLHttpRequest can return the response of a WEB server synchronously or asynchronously, and can return content in the form of text or a DOM document. It can receive any form of text document and is a key feature of the AJAX WEB application architecture.

The previous article says that XMLHttpRequest can receive any form of documentation, so it is necessary to mention the two data formats commonly used in network transmissions.

Two commonly used data formats XML and JSON?

Xml:

XML definition: Extensible Markup Language, a markup language that is used to mark electronic files for structural purposes.

Specification FOR XML:

1, must have a root element
2. No spaces, no numbers, no digits or. Sensitive to the beginning and case
3, not cross nesting
4, property double quotes (browser automatically corrected to double quotes)
5, special symbols to use the entity
6, comments and HTML like

Although complex data can be described and transmitted, its resolution is too complex and bulky, so implementation development is rarely used.

XML Usage Steps Brief:

Because XML is a DOM object, you can direct the DOM method,

1, var xml=xhr.responsexml; get XML (PHP-given interface)

2, var items=xml.queryselector (' item '); Get XML document Structure

3. String stitching

3.1, the initialization of Var html= ';

3.2, traverse for () {get data var item=item[i],} stitching html+= ' tag + data '

4, rendering Document.queryselector (' tbody '). innerhthml=html

Json:

JSON definition: JavaScript Object notation, another lightweight text data Interchange format, independent of language.

The specification for JSON:

1, the data in the name/value pair
2, the data is separated by commas (last health/value pair can not be comma)
3, curly braces Save the object square brackets Save the array
4. Use double quotes

Cross-language parsing of JSON:

When JSON data is transmitted in different languages, the type is a string, and each language has its own parsing method, which needs parsing to be completed before it can be read.

1. PHP Parsing method

Array to JSON character json_encode-> $json _array = Json_encode ($array);

JSON character to array json_decode-> $array _json = Json_decode ($json _array);

2. Javascript Parsing method

String to Object Parse->var Jsonobj=json.parse (JSONSTR);

object to the String Stringify->var jsonstr=json.stringify (jsonobj);

Tips:json compatible processing Reference json2.js

XMLHttpRequest in the event monitor onreadystatechange?

The above AJAX application must master the key knowledge (sharing) is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.

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.