vikmalhotra
vikmalhotra

Reputation: 10071

getJSON function always returns null

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&tagmode=any&format=json&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

Upvotes: 0

Views: 1351

Answers (2)

vikmalhotra
vikmalhotra

Reputation: 10071

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.

Upvotes: 0

Reigel Gallarde
Reigel Gallarde

Reputation: 65264

@Reigel - no its not on the same domain.

your problem is because of the same-origin-policy

Upvotes: 1

Related Questions