<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jsonp跨域</title>
</head>
<body>
<button id="btn">get</button>
<p id="text"></p>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$("#btn").click(function(){
$.ajax({
type: "get",
url: "http://api.money.126.net/data/feed/0000001,1399001?callback=refreshPrice",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback:"refreshPrice",
success: function(data){
$("#text").html(data['0000001'].name + data['0000001'].price);
},
error: function(){
alert('fail');
}
});
});
</script>
</body>
</html>
使用JSONP解决跨域问题的实例
最新推荐文章于 2025-05-23 06:48:24 发布