jsonp

1.为什么会跨域?

因为同源策略,只要协议,端口号,或者域名有一个不一样,就是跨域。

2.为什么要运用回调函数?

如果没有这个回调函数,你怎么获得请求过来的数据呢?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JSONP 实例</title>
</head>
<body>
<div id="divCustomers"></div>
<script type="text/javascript">
function callbackFunction(result)
{
document.getElementById('divCustomers').innerHTML =result;
}
</script>
<script type="text/javascript" src="https://www.runoob.com/try/ajax/jsonp.php?jsoncallback=callbackFunction"></script>
</body>
</html>

 

posted @ 2019-07-31 15:28  putaopi  阅读(177)  评论(0)    收藏  举报