简体   繁体   English

getJSON函数始终返回null

[英]getJSON function always returns null

I am trying to make a get http request using jquery getJSON function. 我正在尝试使用jquery getJSON函数发出一个get http请求。 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. 这总是返回null。 I have checked the HTTP Headers, they are null as well. 我已经检查了HTTP标头,它们也为null。 But if I directly use the URL, it displays JSON in the browser window. 但是,如果我直接使用该URL,它将在浏览器窗口中显示JSON。

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. 有人建议我应该使用JSONP,但是我将实际使用的URL中有一些我不想透露的敏感信息,因此我想坚持使用getJSON。

Regards 问候

@Reigel - no its not on the same domain. @Reigel-否不在同一域中。

your problem is because of the same-origin-policy 您的问题是由于原产地政策

正如@Reigel所建议的那样,问题出自于同源策略,因此我决定通过使用基于服务器的代码(返回正确的json)来创建代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM