Ajax Chrome扩展(根据官方教程制作)不工作
这个教程还可以吗?我已经下载了所有的文件,扩展名不起作用。我认为Ajax请求有一个问题 我得到了信息: 无法显示图像。谷歌图片没有回应Ajax Chrome扩展(根据官方教程制作)不工作,ajax,google-chrome,Ajax,Google Chrome,这个教程还可以吗?我已经下载了所有的文件,扩展名不起作用。我认为Ajax请求有一个问题 我得到了信息: 无法显示图像。谷歌图片没有回应 我试图对另一个网站执行Ajax请求,但结果表明该请求是在本地执行的——尽管在menifest.json文件中有权限。在本例中,在第60行的popup.js中,调用了。现在已经过期了 您可以通过提供查询参数进行验证。例如 将给出响应“此API不再可用” 本论坛讨论备选搜索API列表。 是的,所以这个还是坏的。我修补了popup.js文件(下面的链接)以使用goog
我试图对另一个网站执行Ajax请求,但结果表明该请求是在本地执行的——尽管在menifest.json文件中有权限。在本例中,在第60行的popup.js中,调用了。现在已经过期了 您可以通过提供查询参数进行验证。例如 将给出响应“此API不再可用” 本论坛讨论备选搜索API列表。
是的,所以这个还是坏的。我修补了popup.js文件(下面的链接)以使用googleapis(UberHans发布的备选方案中提到)。我试图找到一个来源回购公关的变化,但没有这样的运气 popup.js要求您添加cx和api密钥。如果您阅读了代码,那么应该非常清楚您需要更改什么以及如何获取所需的cx和api密钥 更新:如果有帮助的话,下面是google提供的和我为使示例正常工作所做的区别(cx和key变量需要使用有效的cx和key更新才能正常工作):
59,61c59,66
< // https://developers.google.com/image-search/
// https://developers.google.com/custom-search/json-api/v1/using_rest
>var cx='从以下位置插入您的cx:https://cse.google.com'
>//警告:在代码中硬编码api密钥确实不安全
>var key='从以下位置插入密钥:https://console.developers.google.com'
>var searchUrl=https://www.googleapis.com/customsearch/v1?searchType=image'
>+'&cx='+encodeURIComponent(cx)
>+'&key='+encodeURIComponent(key)
>+'&q='+encodeURIComponent(搜索术语);
69,72c74,76
如果(!response | | |!response.items | |!response.items.length){
>errorCallback('谷歌图像搜索没有响应')
>返回;
74c78
var firstResult=response.items[0];
77,79c81,83
var imageUrl=firstResult.image.thumbnailLink;
>var width=parseInt(firstResult.image.thumbnailWidth);
>var height=parseInt(firstResult.image.thumbnailHeight);
除非您确实需要该特定功能,否则您可以尝试其他示例
这是相同的想法已修复。是的,教程既旧又有缺陷。这是执行Ajax请求的一个问题。我向谷歌抱怨过。它最终成功了吗?已经5个月了,谷歌对你的抱怨毫不在乎。感谢你问这个问题+1请发布你的解决方案。一年后也不在乎。教程直到不起作用。除非你真的想要这个特定功能,否则你可以尝试其他示例。这与Anks的帮助是一样的。下面是另一个好的例子,我创建自定义搜索的目的是什么?我尝试为images.google.com创建一个,但得到了
accessNotConfigured
。
59,61c59,66
< // https://developers.google.com/image-search/
< var searchUrl = 'https://ajax.googleapis.com/ajax/services/search/images' +
< '?v=1.0&q=' + encodeURIComponent(searchTerm);
---
> // https://developers.google.com/custom-search/json-api/v1/using_rest
> var cx = 'insert-your-cx-from:https://cse.google.com'
> // WARNING: Hard-coding your api key in code is really insecure
> var key = 'insert-your-key-from:https://console.developers.google.com'
> var searchUrl = 'https://www.googleapis.com/customsearch/v1?searchType=image'
> + '&cx=' + encodeURIComponent(cx)
> + '&key=' + encodeURIComponent(key)
> + '&q=' + encodeURIComponent(searchTerm);
69,72c74,76
< if (!response || !response.responseData || !response.responseData.results ||
< response.responseData.results.length === 0) {
< errorCallback('No response from Google Image search!');
< return;
---
> if (!response || !response.items || !response.items.length) {
> errorCallback('No response from Google Image search')
> return;
74c78
< var firstResult = response.responseData.results[0];
---
> var firstResult = response.items[0];
77,79c81,83
< var imageUrl = firstResult.tbUrl;
< var width = parseInt(firstResult.tbWidth);
< var height = parseInt(firstResult.tbHeight);
---
> var imageUrl = firstResult.image.thumbnailLink;
> var width = parseInt(firstResult.image.thumbnailWidth);
> var height = parseInt(firstResult.image.thumbnailHeight);