This paper introduces a way to realize cross-domain by JS: Through server-side proxy.
The specific idea: because the browser has the same origin policy limit , (homologous strategy namely: Https://developer.mozilla.org/zh-CN/docs/Web/Security/Same-origin_policy), Therefore, to cross-domain access to resources under other domains, you need to bypass this restriction of the browser, you can set up a proxy on the server side, the server side of the cross-domain site to make requests, and then return the request results to the front end, to successfully avoid the same-origin policy restrictions.
Here's how:
1. In localhost:81/a.html, make a request to an agent under homologous
$.ajax ({ URL: '/proxy.php?name=hello&info=information ', //server-side agent type: ' GET ', success: function () {}})
2, in the agent proxy.php, to the non-homologous server issued a request, obtain the results of the request, the results are returned to the front end.
<?php $name =$_get[' name ']; $info = $_get[' info ']; $crossUrl = ' http://b.com/sub?name= '. $name; Make a request to another domain $res = file_get_contents ($CROSSURL); echo $res; ? >
---server-side proxy implementation of Ajax cross-domain