JSONP
When it comes to JSONP, it's about homologous strategy (same origin policy), which is the most central and basic security feature of the browser.
The browser's same-origin policy restricts the "document" or script from different sources to read or write to the current "document" or set certain properties.
The popular argument is that foreign scripts cannot touch their own documents.
There are four factors that affect the source: hostname host, subdomain, port, protocol.
JSONP (JSON with padding). This is a way to fetch data from a remote server. The principle is that by creating a script tag, the external file contains a piece of JSON data that is returned by the server and wrapped in a function call as a parameter. Script tags get scripts files that are not subject to cross-domain restrictions (as well as labels that have the ability to load data across domains: IMG, iframe, link, and so on are not restricted by the same-origin policy), and all browsers support this technology.
First, add a script tag to the head.
<script src="Http://example.com/data.json"></script>
Pre-defined global functions, waiting for method calls in the returned data
window.jsoncallback = function (Result) {//handles the related logic that returns the result}
">window . Jsoncallback = function {//related logic for returning results }
The data in the requested file is a method that has data as a parameter, the script is executed after the data is loaded into the browser, and the method is called (the method is already defined)
jsonCallback({"data":"foo"});
Fortunately, JQ has wrapped it up.
Jquery.getjson ("Http://example.com/data.json", function() {//Handle related logic for returning results})