js通信——同源跨域

JavaScript014

js通信——同源跨域,第1张

同源:协议、域名、端口号都相同。

同源策略限制:从一个源加载的文档或脚本与另一个源的资源进行交互。

限制:1.cookie、localstorage、indexDB不能获取;2. ajax请求不能发送;3.DOM无法获得。

ajax 同源、fetch、webSocket 不限制同源、CORS 支持同源、不同源

$(document).ready(function(){

$("#b01").click(function(){

htmlobj=$.ajax({url:"/jquery/test1.txt",async:false})

$("#myDiv").html(htmlobj.responseText)

})

})