我已经设法弄清楚如何调用我的tumblr api并取回什么 我需要。只要我对地址和地址进行硬编码,它就能正常工作 getJSON调用中的其他变量。我尝试使用的那一刻 调用区域中的变量,它试图打开我的硬盘上的文件或 它剥离了我的网址开头的“http:”。
我做错了什么?
<!DOCTYPE html>
<head>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
SkipNbr = 0;
GetNbr = 50;
var a = "http://api.tumblr.com/v2/blog/";
var bname = "[myblogname].tumblr.com";
var c = "/posts/photo?api_key=";
var MyAPIkey = "myAPIkey";
var xx = "&limit="+GetNbr+"&offest="+SkipNbr+"?jsonp=?";
var callstring = "'"+a+bname+c+MyAPIkey+xx+"'";
console.log(callstring);
$.getJSON(callstring, function (data) {
// $.getJSON("http://api.tumblr.com/v2/blog/[myblogname].tumblr.com/posts/photo?api_key=[myAPIkey]&limit=GetNbr&offset=SkipNbr&jsonp=?", function (data) {
console.log(data.response.posts[0].caption);
$.each(data.response.posts, function (i, data) {
$("div").append(i+1 + " " + data.tags.toString() + "<br>");
});
});
});
});
</script>
<script type="text/javascript">
function myFunction()
{
SkipNbr = 0;
GetNbr = 50;
$.getJSON("http://api.tumblr.com/v2/blog/[myblogname].tumblr.com/posts/photo?api_key= [myAPIkey]&limit=GetNbr&offset=SkipNbr&jsonp=?", function (data) {
console.log(data.response.posts[0].caption);
alert(data.response.posts[0].caption);
$.each(data.response.posts, function (i, data) {
$("div").append(i+1 + " " + data.tags.toString() + "<br>");
});
}
</script>
</head>
<body>
<button>Get JSON data</button>
<script type="text/javascript">
//call after page loaded
// window.onload=myfunction();
</script>
<div></div>
</body>
</html>
答案 0 :(得分:0)
这样:
var callstring = "'"+a+bname+c+MyAPIkey+xx+"'";
应该是这样的:
var callstring = a+bname+c+MyAPIkey+xx;