user2511446
user2511446

Reputation: 23

Cant seem to get my jsonp to work. What am i doing wrong here?

I've started building my website 2 weeks ago and have learnt HTML,CSS and a bit of javascrip so far but i cant seem to be able to get the following code to work for my site:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

    $.getJSON("http://blockchain.info/ticker?callback=?",function(result){
       document.getElementById("testspan").innerHTML=result.EUR.last;
    });

});

</script>
</head>

<body>
<ul>
<li>test: <span id="testspan">test</span>
</ul>

</div>

What is basicly want is to get the data from "http://blockchain.info/ticker" to show in my list item. But only the EUR.last specific value.

Many thx in advance!

Upvotes: 2

Views: 205

Answers (1)

lonesomeday
lonesomeday

Reputation: 237817

That site does not support JSONP, which is what you are attempting to use with callback=?. The idea here is that you will get a Javascript function call wrapping the object, which makes cross-domain Javascript requests possible.

If we try it by looking at http://blockchain.info/ticker?callback=functionName, you will see that the page does not have a function call. JSONP is therefore not supported and you will need to find another way of doing this, perhaps with a proxy on your own server.

Upvotes: 3

Related Questions