协议、端口、和域名有任意一个不同就会造成跨域。
http://www.baidu.com/src/home/index.html
请求地址 | 形式 | 结果 |
http://www.baidu.com/test/a.html | 同一域名,不同文件夹 | 成功 |
http://www.baidu.com/src/home/index.html | 同一域名,统一文件夹 | 成功 |
http://www.baidus.com/src/home/index.html | 不同域名,文件路径相同 | 失败 |
http://www.baidu.com:8080/src/home/index.html | 同一域名,不同端口 | 失败 |
https://www.baidu.com/src/home/index.html | 同一域名,不同协议 | 失败 |
同源策略:
请求的url地址,必须与浏览器上的url地址处于同域上,也就是域名,端口,协议相同.