加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

JSONP

发布时间:2020-12-16 19:38:53 所属栏目:百科 来源:网络整理
导读:http://www.cnblogs.com/chopper/archive/2012/03/24/2403945.html 总结一下: 1. 使用script tag实现跨域访问 本地建立2个http server:A (localhost:20001) 和B( localhost:20002 ) 用户使用浏览器访问A的index.html,test.js保存在B中 index.html如下: ht

http://www.cnblogs.com/chopper/archive/2012/03/24/2403945.html


总结一下:

1. 使用script tag实现跨域访问

本地建立2个http server:A(localhost:20001)和B(localhost:20002)

用户使用浏览器访问A的index.html,test.js保存在B中

index.html如下:

<html >
<head>
<title>test</title>

<script>

function callback(data) {
alert(data.message);
}

</script>
<script type="text/javascript" src="http://localhost:20002/test.js"></script>
</head>
<body>
</body>
</html>


test.js如下:

callback({message:"success"});


运行结果:弹出“success”的对话框


2. 客户端和服务端规定JSONP协议,完成跨域数据传输

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读