84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
$.getJSON('http://changyan.sohu.com/api/...',function(res){
console.log(res); }); 跨域问题
人生最曼妙的风景,竟是内心的淡定与从容!
纯前端处理,也就是使用jsonp方式,需要同另一端配合约定才行。很显然你不满足这种情况。所以,推荐使用服务端代理的方式,可以通过nginx代理,或者其他服务器代理。当然,也可以通过服务端代码的方式代理,也即通过服务端一个中转访问而已。
前端不允许跨域。所以你还是通过服务器抓页面吧。
当然如果你能控制被跨域的网站,可以使用jsonp不过我个人推荐控制header设置Access-Control-Allow-Origin来允许跨域
纯前端处理,也就是使用jsonp方式,需要同另一端配合约定才行。很显然你不满足这种情况。
所以,推荐使用服务端代理的方式,可以通过nginx代理,或者其他服务器代理。
当然,也可以通过服务端代码的方式代理,也即通过服务端一个中转访问而已。
前端不允许跨域。
所以你还是通过服务器抓页面吧。
当然如果你能控制被跨域的网站,可以使用jsonp
不过我个人推荐控制header
设置
Access-Control-Allow-Origin
来允许跨域