協議+域名+端有一個不同就會產生跨域。,常見跨域解決方案:
1、 通過jsonp跨域(jsonp缺點:只能實現get一種請求)
2、 document.domain + iframe跨域
3、 location.hash + iframe
4、 window.name + iframe跨域
5、 postMessage跨域
6、 跨域資源共享(CORS)
response.setHeader("Access-Control-Allow-Origin", "http://localhost:9105");(也可以設置為 * 表示該資源誰都可以用)
response.setHeader("Access-Control-Allow-Credentials", "true");(若要帶cookie請求:前后端都需要設置)
springMVC的版本在4.2或以上版本,可以使用注解實現跨域,方法上添加:@CrossOrigin(origins="http://localhost:9105",allowCredentials="true")
7、 nginx代理跨域
8、 nodejs中間件代理跨域
9、 WebSocket協議跨域