Wednesday, 11 September 2013

Getting data from external server with JSONP

Getting data from external server with JSONP

Im trying to get some data from a web api on an external server. I can see
the right data under Network -> Response in Chrome debugger.
If i replace my url with a flicker JSON url i get a success. I can see in
the Response that the data is show differently, but i dont know how to
change my data to the same as flickr.
I made a Fiddle to demonstrate my problem: jsfiddle/8JDna/2/
<body>
<div id="content">
<div class="well">
</div>
</div>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</body>
$(function () {
var thisMonth = 0;
var flickrURL =
'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?';
var myURL = 'http://driving.thylle.dk/api/distance?jsoncallback=?';
$.ajax({
url: myURL,
jsonp: "callback",
dataType: "jsonp",
data: {
format: "json"
},
success: function (data) {
$(".well").html("<h3> SUCCESS </h3>");
},
error: function (xhr, textStatus, errorThrown) {
$(".well" ).html("Error: " + textStatus + ": " + errorThrown);
},
});
});
I hope you can understand my question
Best regards Rasmus

No comments:

Post a Comment