Home > Web Front-end > JS Tutorial > Detailed explanation of how to implement Javascript cross-domain request code

Detailed explanation of how to implement Javascript cross-domain request code

伊谢尔伦
Release: 2017-07-20 11:39:22
Original
1555 people have browsed it

Under what circumstances will cross-domain occur?

Assume that the domain name is: http://www.php.cn
If the requested domain name is different from this domain name, this situation is cross-domain. Since there are loopholes in cross-domain, it is generally For example, normal cross-domain request methods cannot be requested.
Solution:
1. window.name
1. The server returns

<script>window.name=&#39;{"id":"3", "name":"leisure"}&#39;;</script>
Copy after login

2. Define an iframe and add the onload event< ;iframe id="iframe1" onload="iLoad">