javascript - 前后端分离后你们是如何解决跨域问题的
伊谢尔伦
伊谢尔伦 2017-04-18 10:55:24
0
12
1225

联调接口 后台完全不管 目前准备用jsonp来做跨域 想问各位有没有什么更好的解决方法

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(12)
Peter_Zhu

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。。。。

Ty80

CORS. Since it is front-end and back-end analysis, just set the header in the background

Ty80

This time I will start a node server to forward the request

Ty80

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.

Peter_Zhu

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?

PHPzhong

No need for jsonp, it’s too inconvenient

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template