views:

83

answers:

3

Hello all

I am trying to make a get http request using jquery getJSON function. I have implemented it like this...

<script type="text/javascript">
$(function(){
$("#query").keyup(function(event) {
        keyword = $("#query").val();
        $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&amp;tagmode=any&amp;format=json&amp;jsoncallback=?", showdata );
    });
});
function showdata(data, status) {
    alert(data + ":" + status);
}
</script>

This always returns null. I have checked the HTTP Headers, they are null as well. But if I directly use the URL, it displays JSON in the browser window.

What am I doing wrong?

Some suggested I should use JSONP, but in the URL I will actually using, there is some sensitive information which I don't want to reveal, so I want to stick with getJSON.

Regards

A: 

Nothing really wrong here. Try to declare showdata() before your .getJSON() call.

example: http://www.jsfiddle.net/htcxT/1/

Which jQuery version are you running?

jAndy
@jAndy - nothing. even putting the function showdata() before the getJSON call returns null. I am using jquery.1.4.2.
ShiVik
+1  A: 

@Reigel - no its not on the same domain.

your problem is because of the same-origin-policy

Reigel
@Reigel - So does this mean that I have to use JSONP? Also why was the flicker api working over here - api.jquery.com/jquery.getJSON and not my api?
ShiVik
it's because of `jsoncallback=?` which is JSONP...
Reigel
@Reigel: would you mind to explain why http://www.jsfiddle.net/htcxT/1/ works ? It's the exact same code from OP
jAndy
@jAndy - both works. the only thing is, the OP's url was just an example... The OP's real url is not in the same domain and not using JSONP.
Reigel
A: 

As @Reigel suggested the problem was of same-origin-policy, so I have decided to create a proxy by using a server-based code which returns the correct json.

ShiVik