First, Ajax cross-domain overview
Homologous policy
-Homologous strategy (same origin policy) is a convention, which is the core of the browser and the most basic core. If the same origin policy is missing, the browser's normal functionality may be affected. It can be said that the Web is built on the basis of the same-origin strategy, the browser is only for the same Origin policy implementation
-It is a well-known security strategy presented by Netscape
-Now all JavaScript-enabled browsers will use this policy
-the so-called homologous policy refers to the same domain name, protocol, port
Domain Name Overview
-Domain name is the name of a computer or group of computers on the Internet consisting of a string of dotted names used to identify the electronic orientation of the computer during data transfer
-The purpose of the domain name is to facilitate the memory and communication of the address of a group of servers
-Top-level domain
-Level Two domain name
-Level Three domain name
A different domain
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7E/7E/wKiom1cCRe-yAFPXAAHmAHmdETc804.png "title=" Web.png "alt=" Wkiom1ccre-yafpxaahmahmdetc804.png "/>
Cross-Domain Overview
-Simply put, for security reasons, JavaScript on the page cannot access data on other servers, that is, "same-origin policy." Cross-domain is a way to circumvent the same-origin policy restrictions. Achieve the effect of communication between different servers.
-As long as the protocol, domain name, port is any different, are considered to be different domains
Second, Ajax cross-domain implementation
JSONP Overview
-JSONP (JSON with Padding) is a usage pattern of JSON that can be used to solve the problem of cross-domain data access for mainstream browsers
-Because of the same-origin policy, Web pages that are generally located in server1.example.com cannot communicate with servers that are not server1.example.com, while HTML <script> elements are an exception. With this open strategy of <script> elements, the Web page can get JSON data generated from other dynamic, and this usage pattern is called JSONP
$.getjson ()
The-$.getjson () method allows you to load JSON data for other domains by using a callback function in the form of JSONP
-Using the $.getjson () method to implement cross-domain requests, you need to add "callback=?" after the URL of the request path, and jquery will automatically replace the "?" is the correct function name to execute the callback function
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7E/7B/wKioL1cCSGGA7SB5AACp36vGB-A147.png "title=" Web.png "alt=" Wkiol1ccsgga7sb5aacp36vgb-a147.png "/>
$.ajax ()
The-$.ajax () method can also use JSONP to implement cross-domain requests by setting the value of the option "DataType" of the $.ajax () method to "Jsonp" only.
-Options for $.ajax ()
-DataType-Sets the data type returned by the server, which needs to be set to "Jsonp"
-Jsonpcallback-Specifies a callback function name for the JSONP request, which will be used in place of jquery auto-generated random function names
-Jsonp-Rewrite the name of the callback function in a JSONP request, which will be used instead of "callback=?"
Summary: This chapter mainly introduces the Ajax cross-domain request (Ajax cross-domain overview, Ajax cross-domain implementation)
This article from the "Flying Ants" blog, declined to reprint!
JavaScript's Ajax-7 Ajax cross-domain request (Ajax cross-domain overview, Ajax cross-domain implementation)