一定要坚持下去的前端面试题--网络协议

88 阅读1分钟

浏览器同源策略

1. 什么是跨域

2. 如何解决跨域

(1) CORS

(2) JSONP

a. 原理

JSONP利用

b. 缺点

  • 只支持GET请求
  • JSONP的错误处理机制并不完善

(3) WebSocket

(4) postMessage

(5) window.name + iframe

(6) document.domain + iframe

(7) nginx代理