Traditional http request, ajax request, jsonp request

Traditional http request

In a traditional http request, the server will return an HTML web page, the data is stored in the web page, and the browser needs to refresh the entire page when it receives the data.

ajax request

The result of ajax request (Asynchronous JavaScript and XML) is json or xml data, and if the data needs to be updated, there is no need to refresh the entire page. So as to realize the fast response of the browser.

The principle and process of AJAX asynchronous request The
difference between AJAX request and ordinary HTTP request

jsonp request

Ajax requests have the problem of cross-domain inaccessibility, and cross-domain access needs to be set up by proxy.
But the jsonp request is resolvedGet type The cross-domain problem of ajax requests, in fact, jsonp requests are general requests.
1. In our front-end page, we need to request the data in the back-end server. Because of the security measures of the browser, we can only request access under the same domain name. Cross-domain requests can be realized by setting up a proxy.
2. But when using ordinary img tags to get pictures from the network, we found that they can be accessed across domains, just like the following, jsonp request uses this principle.

<img src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png">

3. Here comes the point, what is the basic principle of jspon?
When the front-end sends a request, it will provide a parameter called callback (callback function) to the back-end server. When the back-end receives the request, it will return a function call statement, and the returned data will be passed in as the function parameter. The front end will execute this callback function after receiving the data, so that the data request is realized.
Learn more about jsonp request:
JSONP cross-domain request principle and example
Jsonp request

Guess you like

Origin blog.csdn.net/qq_44606064/article/details/115371245