What you need to know in AJAX applications!

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, based on the HTTP protocol.

The concept of async?

Refers to the execution of a program does not block other program execution, its representation is that the order of execution of the program does not depend on the writing order of the program itself, in contrast to synchronization.

The role of Asynchrony?

The advantage is that it does not block the execution of the program, thereby improving overall execution efficiency.

The core of Ajax?

   XMLHttpRequest, shorthand xhr,xml Extensible Markup Language, HTTP Hypertext Transfer Protocol, request requests. The XMLHttpRequest object can implement a partial update of a 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, as well as normal GET requests. XMLHttpRequest can return the response of the WEB server synchronously or asynchronously, and can return content as text or as 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 kind of document, then we have to mention the two data formats commonly used in network transmission.

Two commonly used data format XML and JSON?

XML:

   XML definition : Extensible Markup Language, a markup language used to mark electronic files to make them structurally.

  specification of XML :

1. Must have a root element
2. No spaces, no numbers or. Start, case sensitive
3. No cross-nesting
4. Attribute double quotation marks (the browser is automatically corrected into double quotes)
5, special symbols to use the entity
6. Annotations are the same as HTML
Although complex data can be described and transmitted, its resolution is too complex and large, so implementation is rarely used.

  Introduction to XML usage steps :

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

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

2. Var items=xml.queryselector (' item '); Get the document structure of XML

3. String concatenation

3.1. Initialize var html= ';

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

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

JSON:

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

  specifications for JSON :

1. Data in name/value pairs
2. Data separated by commas (last health/value pair cannot take commas)
3, curly braces Save the object square brackets Save the array
4. Use double quotation marks

JSON   Cross-language parsing :

When JSON data is transmitted in different languages, the type is a string, and different languages have their own parsing methods, which need to be parsed before they 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 String Stringify->var jsonstr=json.stringify (jsonobj);

   tips: JSON-compatible processing reference json2.js

Event monitoring onreadystatechange in XMLHttpRequest?

Not to be continued ... 2016-08-11 23:43:55

What you need to know in AJAX applications!

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.