使用JsonP进行跨域请求
以前有一个使用Jquery的$.post(…);来发请求想加载其他网站数据的想法,但是弹出如下错误:
XMLHttpRequest cannot load http://s.music.163.com/search/get/?type=1&filterDj=true&s=%E7%88%B1%E5%B0%B1%E7%88%B1%E4%BA%86&limit=3&offset=0. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.
那时候还不知道这个是什么问题, 搜索了下才知道是跨域请求的问题. 后来一直心里记挂着这个事. 于是今天在闲暇之余去了解了一下. 本文会对以Jsonp方式进行的跨域请求解决办法进行说明.