Differences and usage of Ajax and JSONP

First we should know that AJAX and JSONP can communicate with the background, obtain data, and information, but do not need to refresh the entire page, and implement the local refresh of the page.

Let’s take a look at the difference between Ajax and Jsonp.

AJAX and JSONP Differences:

AJAX is a technology that sends an HTTP request and an asynchronous communication in the background. The principle is to instantiate the XMLHTTP object and use this object to communicate with the background.

A complete AJAX request typically includes the following steps:

(1) Instantiate XMLHttpRequest object

(2) Connecting server

(3) transmission Request

(4) Receiving Response Data

JSONP is a data communication format that enables cross-domain transmission HTTP requests, which can be used in AJAX. The principle is to use the Script tag to link resources across domiles.

JSONP consists of two parts: the callback function and data, the callback function is generally controlled by the browser, as a parameter sent to the server side (of course, you can also fix the name of the callback function, but the client and server side Name must be consistent). When the server responds, the server is returned to the data and the data.

JSONP’s requesting process is as follows:

Request phase: The browser creates an Script tag and assigns it to its SRC. Send Request: When the SRC is assigned to Script, the browser will initiate a request.

Data Response: The server will return to the data to be returned as a parameter and function name (format similar “JSONPCALLBACK ({name: ‘ABC’})”). When the browser receives the response data, since Script is initiated, it is equivalent to calling the JSONPCALLBACK method directly and a parameter is incorporated.

Last:Json only supports GET requests, Ajax supports GET and POST requests.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment