jquery is a popular JavaScript library used to simplify DOM operations, event processing, animation effects, etc. The most common application is to request back-end data through Ajax to achieve a page refresh-free experience. However, in some cases, we need to obtain data from multiple different domain names, in which case cross-domain requests are required. This article will introduce how to use jquery to perform cross-domain http request data.
1. What is a cross-domain request?
On the browser side, due to the restrictions of the browser's same-origin policy, it is not allowed to access data under another domain name from a page in one domain name, that is, Same-Origin Policy. Homology means that the protocol, domain name, and port number must be exactly the same. For example, https://www.example.com and https://example.com have different origins, and http://www.example.com and http://www.example.org have different origins.
Cross-Origin Request refers to the process of requesting data from one source (domain name, protocol, port number) to another source. In order to implement cross-domain requests, the browser needs to complete a series of security verifications to ensure that the requested data is allowed.
2. Cross-domain request methods
Currently, the more popular cross-domain request methods are as follows:
JSONP is a method to achieve cross-domain communication between different domains by adding the