admin管理员组文章数量:1421730
i'm trying to make my image search with google ajax search i'm using jQuery. so below my code
$.getJSON('.0&q=hello', function(data) {
console.log(data);
});
the console printed NULL and my xhr information is
request URL:.0&q=hello
Request Headers
Accept:application/json, text/javascript, */*
Cache-Control:max-age=0
Origin:
Referer:/thread/create
User-Agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4
i'm not sure what's wong. help me plz
i'm trying to make my image search with google ajax search i'm using jQuery. so below my code
$.getJSON('http://ajax.googleapis./ajax/services/search/images?v=1.0&q=hello', function(data) {
console.log(data);
});
the console printed NULL and my xhr information is
request URL:http://ajax.googleapis./ajax/services/search/images?v=1.0&q=hello
Request Headers
Accept:application/json, text/javascript, */*
Cache-Control:max-age=0
Origin:http://example.local
Referer:http://example.local/thread/create
User-Agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Safari/533.4
i'm not sure what's wong. help me plz
Share Improve this question asked Sep 1, 2010 at 1:36 Dae KIMDae KIM 8138 silver badges18 bronze badges1 Answer
Reset to default 8Your URL needs a slight tweak to trigger JSONP, add &callback=?
on the end, like this:
$.getJSON('http://ajax.googleapis./ajax/services/search/images?v=1.0&q=hello&callback=?', function(data) {
console.log(data);
});
You can see it working here, take a look at the console.
If jQuery sees a callback=?
in the url, it replaces it with a function name it generates (which is your function(data)
callback), and that's what gets run when the JSONP request es back. See the $.getJSON()
documentation for the same info.
Without this it's trying to do an XmlHttpRequest, and being blocked by the same-origin policy, since it's on another domain.
本文标签: javascriptgoogle ajax search with jQuerygetJSON() there is any responseStack Overflow
版权声明:本文标题:javascript - google ajax search with jQuery - $.getJSON(). there is any response - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745328933a2653720.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论