0

我已经设法弄清楚如何调用我的 tumblr api 并取回我需要的东西。只要我在 getJSON 调用中硬编码地址和其他变量,它就可以正常工作。当我尝试在调用区域中使用变量时,它会尝试在我的硬盘驱动器上打开一个文件,或者它会在我的 url 开头删除“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>
4

1 回答 1

0

这:

var callstring = "'"+a+bname+c+MyAPIkey+xx+"'";

应该是这样的:

var callstring = a+bname+c+MyAPIkey+xx;
于 2012-08-18T04:00:27.673 回答