I've managed to figure out how to call my tumblr api and get back what I need. It is working fine as long as I hard-code the address and the other variables in the getJSON call. The minute I try to use variables in the call area, it tries to open a file on my harddrive or it strips off the "http:" at the beginning of my url.
What am I doing wrong?
<!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>
this:
var callstring = "'"+a+bname+c+MyAPIkey+xx+"'";
should be this:
var callstring = a+bname+c+MyAPIkey+xx;