In modern browsers, it imposes restrictions on the access to Javacript code, such as a page where JS cannot implement AJAX requests to non-homologous URLs to obtain data. At this point, the browser side will be error:
No ' Access-control-allow-origin ' header is present on the requested resource. Origin ' http://localhost:3000 ' is therefore not allowed access. The response had HTTP status code 401.
This security policy is also generally implemented for server side, such as Laravel, in which case it returns
401 Unauthorized
Most of the time, we need this mechanism. So what's the best way to do that?
A more common solution is to use the Web Proxy
The legend follows several scenarios:
Under normal circumstances, if JS's origin and JS to launch Ajax belong to the same site, then there is no problem.
If there is no homologous, the block
Use proxy to workaround the problem:
Refer to the following article
Https://developer.yahoo.com/javascript/howto-proxy.html
JavaScript uses Web Proxy to implement AJAX Cross-domain communication