More Related Content Similar to Hello communications(cn) Similar to Hello communications(cn) (20) Hello communications(cn)3. Widely-Used Models of CrossDomain jsonp(JSON with Padding) + <script> document.domain + iframe flash + crossdomain.xml server proxy window.name + iframe window.location.hash + polling etc.. 4. Cross Document Messaging cross-origin communication 定义了在 iframes/tabs/window 之间安全的跨源通信方案(using origin security) 定义统一的消息发送 API: PostMessage 提供了 JavaScript 上下文之间的异步消息传递机制 9. XMLHttpRequest Level 2 XmlHttpRequest Level 2 (XHR2)做了诸多改进: cross-origin requests progress events the handling of byte streams for both sending and receiving... XMLHttpRequest Level2 allows for cross-origin XMLHttpRequest using Cross Origin Resource Sharing(CORS) 10. Cross Origin Resource Sharing 简单来说,就是跨域的目标服务器要返回一系列的Headers,通过这些Headers来控制是否同意跨域。 4 Syntax HTTP Response Header 4.1 Access-Control-Allow-Origin 4.2 Access-Control-Max-Age 4.3 Access-Control-Allow-Credentials 4.4 Access-Control-Allow-Methods 4.5 Access-Control-Allow-Headers HTTP Request Header 4.6 Origin HTTP Request Header 4.7 Access-Control-Request-Method 4.8 Access-Control-Request-Headers 11. API client var xhr2 = window.XDomainRequest ? new XDomainRequest : new XMLHttpRequest; xhr2.onload = function(){console.log(xhr2.responseText);} xhr2.open(“GET”,’server..'); xhr2.send(); Crossdomain.php <?php header('Access-Control-Allow-Origin: *'); echo 'hello world.'; Editor's Notes http://newclub.sohu.com/test/leon/h5_message/ http://newclub.sohu.com/test/leon/crossdomain.php