跨域的几种方式:cors.jsonp.iframe

cors:是发起请求时候,传递一个特定参数给跨域的服务器,服务器接收到这个参数后,在responseHeaders里面加一个字段Access-Control-Allow-Origin,

比如你的域名是。www.qq.com,要请求www.baidu.com的接口那么字段内容就是

Access-Control-Allow-Origin:www.qq.com

jsonp:就是给页面动态添加script标签,因为script的src可以加载别的域名的资源,

iframe:借助iframe标签 的内嵌页面,和window.name的跳转任意页面保存上个页面设置的window.name。首先我们在a.html里面内嵌<iframe>b.html(和a是不同源)</iframe>,然后在b.html里面请求b的域名的数据,请求回来后保存在window.name中,此时在跳转到和a.html同源的c.html中,这样c.html里面的window.name就是b.html请求的数据,并且c.html和a.html同源,在C里面直接parent.update(window.name)//update是a页面的方法,这样就将window.name里面保存的b页面请求的数据传给了a页面。

猜你喜欢

转载自blog.csdn.net/A13330069275/article/details/83384187