• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

处理相对图像路径ajax

用户头像
it1352
帮助1

问题说明

我正在开发一个小型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!

正确答案

#1

解决方案是不使用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!

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcgjgja
系列文章
更多 icon
同类精品
更多 icon
继续加载