【发布时间】:2015-03-17 05:33:46
【问题描述】:
我是 ajax 新手。我尝试使用 ajax get 方法进行 Google 图片搜索(已弃用的 API)。由于某些原因,我的客户更喜欢 Deprecated API 而不是自定义搜索。当我提出请求时,它会说
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&start=0&imgsz=xlarge,large&q=apple. This can be fixed by moving the resource to the same domain or enabling CORS.
但是当我通过浏览器 url 调用它时,它会以完美的响应响应。
我的 ajax 请求
$.ajax({
type : "GET",
url : "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&start=0&imgsz=xlarge,large&q=apple",
beforeSend : function(xhr) {
xhr.setRequestHeader('Referer', 'http://www.mydomainexample.com');
},
success : function(result) {
console.log(result)
},
error : function(error) {
console.log(error)
}
})
请原谅我的任何错误。请帮帮我。
【问题讨论】:
标签: jquery ajax google-search-api google-image-search