jsonP客户端代码

来源:互联网 发布:如果让宝贝上淘宝首页 编辑:程序博客网 时间:2024/05/17 08:19

<html>
<head>
<script type='text/javascript'>
function mycallback(record) {
alert(record);//record是返回的数据
}

function jsonPRequest(){
var url = 'http://www.xxx.com/jsonP/request_data.php?callback=mycallback';
var script = document.createElement('script');
script.setAttribute('src',url);
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
</head>
<body>
<!-- 点此按钮请求数据 -->
<button onclick='void jsonPRequest();'>请求数据</button>
</body>
</html>