Traditional Culture Encyclopedia - Weather forecast - What does cross-domain ajax mean? Can you give a simple example to illustrate?

What does cross-domain ajax mean? Can you give a simple example to illustrate?

Ajax requests a web resource whose destination address is not the local domain (protocol, domain name and port are different), and obtains external application data according to the response. For example, when we use Ajax to access public service interfaces such as city weather forecast and IP address, it involves cross-domain. When we request external services, the browser will refuse to grant access based on security issues. However, there is no cross-domain problem with the src attribute of script, script and iframe tags, so Ajax takes advantage of this and JSON support across domains. As long as you respond to Ajax requests with a piece of JSON code or JSON data, Ajax can get external services.

For example, jquery's getScript.

$. getscript ("//pv.sohu.com/cityjson", function(){// prefix ame:? Beijing}

//Before the callback function is executed, the js code provided by the external service for the response has been loaded locally and can be used directly.

console.log("cid? :?" ? +? returncitysn . cid);

console.log("cip? :?" ? +? returncitysn . CIP);

console.log("cname? :?" ? +? returncitysn . cname);

});