52,797
社区成员
发帖
与我相关
我的任务
分享
<script type ="text/javascript">
onload = function() {
var xhr = new XMLHttpRequest();
var url = "http://services.digg.com/stories/top?appkey=http%3A%2F%2Fmashup.com&type=javascript&callback=?";
xhr.open("get", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var jsonData = eval("(" + xhr.responseText + ")"); //得到JSON对象
alert(jsonData.stories.length); //得到json数据数量
//......
}
}
}
xhr.send();
}
</script>
<script type="text/javascript">
$().ready(function() {
var url = "http://services.digg.com/stories/top?appkey=http%3A%2F%2Fmashup.com&type=javascript&callback=?";
$.getJSON(url, function(data) {
alert(data.stories.length);
});
});
</script>