Sharing the cross-domain is not only because of the increasing number of jobs that are now being encountered, but also often asked during interviews.
So what is cross-domain, let's take a look at the official explanation: The browser is not able to execute scripts from other websites. It is caused by the browser's homologous policy (the so-called homology refers to the domain name, protocol, ports are the same, as long as there is a different cross-domain ), is the browser security restrictions imposed on JavaScript. Here do not focus on the introduction of the Internet has a lot of this aspect of the introduction, this article mainly detailed jsonp of the underlying implementation principle.
Although the browser is limited in this regard, but we can use the script tag, cleverly avoid the same-origin strategy, "rescue", we look at a code
<script> function fn (data) { console.log (data); } </script><script> fn ("I'm back-end data"); </script>
Nani??? Isn't this just a normal function call that can't be normal? A lot of small partners must think I put the code wrong, open a joke, this is not an ordinary can not be called in the normal function? Does this have a half-penny relationship with the jsonp you're talking about? I want to say that it is not only related, but also very related, and even this is the underlying implementation of the JSONP principle. You're crazy!!! Don't worry ... Let's keep looking down.
Let me take a look at the Baidu hint used in the cross-domain, he is using the form of JSONP, Https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=a&cb=hello, (The parameters after the interface I will explain below) This is the Baidu hint of an interface, we put in the browser's address bar to open
Cross-domain JSONP, the underlying implementation principle