处理相对图像路径ajax [英] Handle Relative Image Paths ajax

查看:120
本文介绍了处理相对图像路径ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型Google Chrome浏览器扩展程序,用于屏幕抓取某个网站。问题是,因为该网站使用相对路径的链接会被打破,我得到了很多这样的错误:

I'm developing a small Google chrome extension that screen scrapes a certain website. The problem is that because that website uses relative paths the links become broken and I get lots of errors like this:

GET chrome-extension://higopdenpioddpmobbehnbcadeenihic/html/images/ico_aAO.gif
GET chrome-extension://higopdenpioddpmobbehnbcadeenihic/html/images/ico_dAO.gif

有什么办法可以避免这些错误?

Is there any way to avoid these errors?

我用来进行GET调用的代码是:

The code I'm using for making the GET call is:

 $.ajax({
        url: searchUrl,
        type: "GET",
        data: {
            'pal': query
        },
        success: function() {
        },
        error: function() {
        }
    });

谢谢!

Thanks!

推荐答案

解决方案是不使用jQuery来解析文档。如果你愿意,你可以使用 jQuery.ajax ,但不要使用 $ 来解析结果。

The solution is to not use jQuery to parse the document. You can use jQuery.ajax if you want to, but do not use $ to parse the result.

请阅读控制台显示有关内容安全策略和大量失败的GET请求的错误,以了解和解决您的问题。

Read the answer to Console shows error about Content Security policy and lots of failed GET requests to understand and solve your problem.

答案强烈建议使用vanilla JavaScript。不过,如果您想使用jQuery,请使用以下DOM解析方法:

The answer strongly recommends to use vanilla JavaScript. If you want to use jQuery nevertheless, use the following DOM parsing method:

// responseText is a string, for example from calling jQuery.ajax
var doc = document.implementation.createHTMLDocument('');
doc.documentElement.innerHTML = responseText;
var $doc = $(doc);
// Enjoy the parsed document without errors!

这篇关于处理相对图像路径ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆