处理相对图像路径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!
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgjgja
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20