javascript - js获取畅言的评论跨域问题怎么解决
黄舟
黄舟 2017-04-11 11:57:34
0
2
355

$.getJSON('http://changyan.sohu.com/api/...',function(res){

    console.log(res);
});
跨域问题
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

répondre à tous(2)
黄舟

纯前端处理,也就是使用jsonp方式,需要同另一端配合约定才行。很显然你不满足这种情况。
所以,推荐使用服务端代理的方式,可以通过nginx代理,或者其他服务器代理。
当然,也可以通过服务端代码的方式代理,也即通过服务端一个中转访问而已。

黄舟

前端不允许跨域。
所以你还是通过服务器抓页面吧。

当然如果你能控制被跨域的网站,可以使用jsonp
不过我个人推荐控制header
设置
Access-Control-Allow-Origin
来允许跨域

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!