JSON、AJAX、JSONP、XML

JSON

json JavaScript Object Notation is the first letter of the abbreviation, is the meaning of the word javascript object notation, said here refers to a similar javascript json object to a data format, the current data format more popular, and gradually replace the traditional xml data format.

JSON is the industry's most widely used data format

JSON is a language-independent and Development, lightweight data format

Vector string JSON

JSON string is just a string, a whole, is not taken, then no way to remove the data stored therein can not be used directly.

Basically all programming languages ​​support JSON, provides the corresponding analytical method

In the WEB data transmission, JSON as text, i.e., a string passed lightweight, and the client is typically operated with a JS received JSON object, between each other so that, JSON object and JSON string conversion, parsing JSON data is the key.

Json advantage

  1. Based on the plain text, cross-platform delivery is extremely simple;
  2. Javascript native support for almost all of the background language support
  3. Lightweight data format, take up less characters, particularly suitable for Internet delivery;
  4. Highly readable, XML Although they are not so clear, but it is still very easy to identify after a reasonable turn indent
  5. Easy to write and parse, the premise is to know the data structure   

 

AJAX

The purpose is to enable javascript ajax technology to send http request, to communicate with the background, access to data and information. Ajax principle of the technique is an example xmlhttp objects, using the object to communicate with the background. Ajax process does not affect the execution of subsequent communications javascript, thereby asynchronous.

Origin policy 
ajax request a page or resource is only following the same domain resources, it can not be resources to other domains, which is based on safety considerations in the design of ajax. ( 'Access-Control-Allow- Origin')

JQ $ .ajax to use
common parameters:

    1. url request address
    2. type request mode, the default is 'GET', commonly used as well as 'POST'
    3. dataType set to return a data format commonly used is 'json' format may be set to 'html'
    4. setting data transmitted to the data server
    5. Set after the success callback request is successful
    6. Set the error callback request failed
    7. async settings are asynchronous, the default value is 'true', showing asynchronous

.AJAX advantage

  1. No refresh update data.
  2. Asynchronous communication with the server.
  3. Front and rear load balancing.
  4. Based standard is widely supported.
  5. Separation of interface and applications.

AJAX shortcomings

  1. AJAX kill the Back and History features, namely the destruction of the browser mechanism.
  2. AJAX-security issues.
  3. Weak support for the search engines.
  4. Exception handling mechanism destruction program. <5>. Contrary to the URL and resource location in mind.
  5. AJAX is not well supported by mobile devices.
  6. The client too fat, too much client code on costs caused by development.

Primeval JS AJAX

https://www.cnblogs.com/colima/p/5339227.html

Ajax works, advantages and disadvantages

https://www.cnblogs.com/yelp/p/3725664.html

 

JSONP

ajax requests only under the same domain data or resources, sometimes need to request data across domains, you need to use jsonp technology, jsonp can request data across domains, its main principle is to use the script tag can link resources across domains characteristic.

JSONP advantage

  1. It is not like XMLHttpRequest object implements Ajax request as limited-origin policy, JSONP can cross-origin policy;
  2. It's better compatibility, can run more ancient browser, no XMLHttpRequest or ActiveX support
  3. After the completion of the request can return results by way of calling callback. The authority callback method to the caller. This is equivalent to the controller layer and the view layer finally separated. jsonp service I provide only provides a pure data services, as for the future provision of services and follow-view page rendering operation by the caller to define themselves just fine. If there are two pages need to render the same data, you only need to have different rendering logic on it, the same logic can be used jsonp service.

JSONP shortcomings

  1. It only supports GET request without support other types like POST HTTP request
  2. It only supports cross-domain HTTP request this case, does not solve the problem of how to make JavaScript calls between two different domains pages.
  3. jsonp when the call failed does not return a variety of HTTP status codes.
  4. The disadvantage is security. In case if the service provided jsonp page injection vulnerability exists, it returns content that is being controlled by the javascript. So what is the result? All calls to this site will jsonp loopholes. So the danger can not be controlled in a domain name ... so when in use to ensure jsonp jsonp must use the service must be safe and reliable

What is jsonp

http://www.bejson.com/knownjson/aboutjsonp/IFjNm1Yvo

 

XML

Extensible markup language (Extensible Markup Language, XML), for marking an electronic document to have a structured markup language, can be used to mark data, defined data types, allow a user to define their own markup language source language . Use XML DTD (document type definition) document type definition to organize data; a unified format, cross-platform and language, has become the industry-accepted standards.
XML is a Standard Generalized Markup Language (SGML) subset is ideal for Web transmission. XML provides a uniform method for describing and exchanging independent of applications or vendors of structured data.

XML advantages

  1. Format unified, standards-compliant
  2. Easy to remotely interact with other systems, data sharing more convenient

XML shortcomings

  1. XML file large, complex file format, transmission bandwidth of accounting
  2. Server and client need to spend a lot of code to parse XML, resulting in server and client code become extremely complex and difficult to maintain
  3. XML parsing inconsistencies between the client the way different browsers, you need to repeat a lot of code
  4. Server-side and client-side parsing XML spend more resources and time

 

Guess you like

Origin www.cnblogs.com/goforxiaobo/p/12635565.html