[Front-end] jsonp principle

A same-origin policy

Same-origin policy, which was presented by a well-known Netscape security policy.
Now all JavaScript-enabled browsers will use this strategy. The so-called homologous refers to the domain, protocol, the same port.
When two tab pages in a browser are open Baidu and Google page
when a Baidu browser execute a script when the script will check which page is part of
that is homologous to check whether, and Baidu only homologous script before It will be executed.

Two jsonp solve cross-domain

1. What is jsonp

JSONP is JSON with Padding abbreviation. It is an unofficial agreement that allows the server returned to the client side integration Script tags, cross-domain access in the form of javascript callback (JSONP this is just a simple realization form)

2. jsonp cross-domain principle

Since the same-origin policy, XMLHttpRequest () object can not be cross-domain, but on the page script js, css style files, images can be cross-domain

1<script type="text/javascript" src="某个cdn地址" ></script>
2<link type="text/css" rel="stylesheet" href="某个cdn地址" />
3<img src="某个cdn地址" alt=""/>

jsonp is dynamically created by a request

Guess you like

Origin blog.csdn.net/cheidou123/article/details/92014269