Cha*_*cer 5 javascript api json
我刚刚开始研究昨晚的JavaScript和jQuery.我正在玩foursquare API(我已经讨厌oauth了,但这可能会在另一个时间里发布另一篇文章)而且当你掌握基本知识时很难,尽管我喜欢这种学习方式.
我的问题很简单,我想从API URL获取数据,不需要身份验证/授权.然后我只想显示它(在我的代码中,我已将其显示为警报onclick).
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
$.getJSON('https://api.foursquare.com/v2/users/self/venuehistory?oauth_token=2ZO1PQOUAD5SXRAJOLZVH53RBQ1EB2C23FE2GUZLJYQUJ3SY&v=20121108',
function (data) {
alert(data);
});
});
});
</script>
</head>
<body>
<button>Send an HTTP POST request to a page and get the result back</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我点击警报时,它会向我提供"[object,Object]",显然这不是我想要的.如何让它显示URL中的数据?
我意识到这是非常基本的(我知道该怎么做,而不是怎么做)非常感谢任何可以帮助我的人.
你不能alert()在JSON对象上做.
相反,试试这个:
alert(JSON.stringify(data));
Run Code Online (Sandbox Code Playgroud)
或者,使用console.log:
console.log(data);
Run Code Online (Sandbox Code Playgroud)