Javascript:将网址传递给谷歌编码有问题

时间:2014-05-04 22:08:40

标签: javascript google-chrome encoding

我正在尝试查看从谷歌反向图片搜索返回的html数据。我传递给谷歌的网址包含一些被编码的字符,特别是?更改为%3F,谷歌似乎不理解格式化的网址(下面的pic_url)。有没有办法发送URL,以便它不会被格式化?或者还有另一种解决这个问题的方法吗?

我的代码如下:

var google_url = "https://www.google.com/searchbyimage?image_url=";

var pic_url = "http://img.cpcdn.com/recipes/_o1f2b886e/50x50c/d9e62798f1c807c1891454bed562e4c9.jpg?u=941483&p=1362455199";

var search_url = google_url + pic_url;

$.getJSON('http://whateverorigin.org/get?url=' + 
                      encodeURIComponent(search_url) + '&callback=?',
                      function(data){
                        $("#targetWrapper").html(data.contents);

                        http_data = data["contents"];
                        console.log(http_data);

            });

我在控制台中收到的错误:

`The requested URL   <code>/searchbyimage%3Fimage_url=http%253A%252F%252Fimg.cpcdn.com%252Frecipes%252F_o1f2b886e%252F50x50c%252Fd9e62798f1c807c1891454bed562e4c9.jpg%253Fu%253D941483%2526amp%253Bp%253D1362455199</code> 
was not found on this server.  
<ins>That’s all we know.</ins>`

但是如果您只是将https://www.google.com/searchbyimage?image_url=http://img.cpcdn.com/recipes/_o1f2b886e/50x50c/d9e62798f1c807c1891454bed562e4c9.jpg?u=941483&amp;p=1362455199复制并粘贴到地址栏就可以了。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

whateverorigin.org中有一个错误: https://github.com/ripper234/Whatever-Origin/issues/1

请注意,建议的解决方案对我不起作用......