日期:2014-05-17 浏览次数:20464 次
<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>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>融化这个BUG。</title> <script type="text/javascript"> var list = null; function callbackFun(o) { list = o; } </script> <script src="http://services.digg.com/stories/top?appkey=http%3A%2F%2Fmashup.com&type=javascript&callback=callbackFun" type="text/javascript"></script> </head> <body> <script type="text/javascript"> document.write(list.count); </script> </body> </html>