Set response.setHeader("Access-Control-Allow-Origin", "*"); in the background You can also configure it on the nginx side to solve the problem. jsonp is not a particularly good method, it has size limitations on the data transferred.
It is not recommended to use jsonp cross-domain. Although this ancient method has good compatibility, it has great limitations and has the risk of XSS. Relatively complete separation of front-end and back-end, of course, means that front-end personnel manage the web server. Of course, this requires relatively high requirements for front-end personnel.
If you just want to adjust the interface, it is better to set up a local test server yourself. It is used as a static server for the page, which is convenient for adjusting the page, and can forward the request and request the data. You can use express yourself, or you can use ready-made ones like browsersync+gulp or webpack+hot reload server.
I use browsersync, the configuration is very convenient, you can refer to this.
Set response.setHeader("Access-Control-Allow-Origin", "*"); in the background
You can also configure it on the nginx side to solve the problem.
jsonp is not a particularly good method, it has size limitations on the data transferred.
CORS。。。。
CORS. Since it is front-end and back-end analysis, just set the header in the background
This time I will start a node server to forward the request
It is not recommended to use jsonp cross-domain. Although this ancient method has good compatibility, it has great limitations and has the risk of XSS.
Relatively complete separation of front-end and back-end, of course, means that front-end personnel manage the web server. Of course, this requires relatively high requirements for front-end personnel.
If you just want to adjust the interface, it is better to set up a local test server yourself. It is used as a static server for the page, which is convenient for adjusting the page, and can forward the request and request the data.
You can use express yourself, or you can use ready-made ones like browsersync+gulp or webpack+hot reload server.
I use browsersync, the configuration is very convenient, you can refer to this.
There is a chrome plug-in, what it does is response.setHeader("Access-Control-Allow-Origin", "*") , just turn it on.
Add nginx
WebSocket is not subject to cross-domain restrictions and can transmit any data, including jsonp.
By the way, shouldn’t this be decided before development? Isn’t it a little late to decide whether it’s jsonp or cors until joint debugging?
No need for jsonp, it’s too inconvenient