浏览器跨域请求是因为分布式才出现的,为了解决这个问题浏览器使用了CORS,一般三种情况会产生跨域请求。
http://www.baidu.com:8080/abcd
http是协议 www是子域名 baidu是域名 8080是端口 abcd是源文件
同源策略
所谓同源是指协议、域名以及端口要相同。
常见的跨域请求
示例:
http://www.yiyuanxinghe.com/index.html 调用 http://www.yiyuanxinghe.com/server.jsp 非跨域
http://www.yiyuanxinghe.com/index.html 调用 http://www.yyxh.com/server.jsp 跨域,主域不同
http://abc.yiyuanxinghe.com/index.html 调用 http://def.yiyuanxinghe.com/server.jsp 跨域,子域名不同
http://www.yiyuanxinghe.com:8080/index.html 调用 http://www.yiyuanxinghe.com/server.jsp 跨域,端口不同
https://www.yiyuanxinghe.com/index.html 调用 http://www.yiyuanxinghe.com/server.jsp 跨域,协议不同
localhost 调用 127.0.0.1 跨域