Must be overlooking something with regards to trying to consume this API. My current attempt is below, but I am not getting an alert with the JSON. What am I missing?
Asked
Active
Viewed 213 times
2 Answers
2
You can't use Ajax requests to call across domains because of the same origin policy in browsers.
You can use JSONP (if the website supports it) otherwise you might need to do it on the server.

Community
- 1
- 1

Jeff the Bear
- 5,603
- 3
- 22
- 18
-
Ok thanks for the reply. So let's say I updated it to a JSONP request. Is it not possible to consume this site via JSONP? http://jsbin.com/uquku4/6/edit – aherrick Dec 24 '10 at 20:36
-
It will depend on whether or not the website you are calling supports JSONP. For example in the jQuery docs Flickr supports it: http://api.jquery.com/jQuery.getJSON/. But I don't know if http://letsbetrends.com/ will (I didn't find anything saying they do from a quick search on google). – Jeff the Bear Dec 24 '10 at 20:43
-
So since it looks like they don't support JSONP do I have ANY other client side options to retrieve the data? – aherrick Dec 24 '10 at 20:49
-
1Probably not, JSONP is dependent on the server supplying the data in a particular format to work (wrapping the JSON data in a function call). Unless there is something similar that the service can do, you won't be able to evaluate the data passed back using the JSONP script trick. – Jeff the Bear Dec 24 '10 at 21:09
-
Got it... seems weird they wouldn't have support for JSONP. Trying to understand why that decision was made as it's obviously limiting the number of people who can use their service... – aherrick Dec 24 '10 at 21:30
0
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var url = 'http://api.whatthetrend.com/api/v2/trends.json?callback=?'
jQuery.getJSON(url, function (data) {
console.info(data);
});
});
</script>
</head>
</html>

Jim G.
- 15,141
- 22
- 103
- 166
-
Thanks for the answer but that is a completely different API... I want to consume the Lets Be Trends API... – aherrick Dec 24 '10 at 21:08
-
Why must you consume the 'Lets Be Trends' API? The 'What The Trend' API appears to solve your underlying problem - That you need to consume Twitter trends on the client. – Jim G. Dec 24 '10 at 21:12
-
Agreed... However Lets Be Trends has a couple different properties they return that I am after. – aherrick Dec 24 '10 at 21:31