图像中的HTML页面的jQuery的负载()不加载 [英] Image not loaded in jQuery load() of a HTML page

查看:104
本文介绍了图像中的HTML页面的jQuery的负载()不加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的code加载HTML页面中的DIV中,

I am using following code to load a html page inside a div,

$("#htmlViewer").load("conversion_test/to_convert_3264/"+getPageName(pageCount)+".htm", function(response, status, xhr) {
                   if (status == "error") {
                     /* var msg = "Sorry but there was an error: ";
                     $("#error").html(msg + xhr.status + " " + xhr.statusText); */
                     jAlert('Unexpected Error : Please try again later', 'Alert');
                     pageCount--;
                   }
                 });

在上面的code,我只得到了HTML文本,但我没有得到CSS和在该网页中的图像。要获得CSS我增加了一个Ajax请求。如果没有这Ajax调用加载的页面不会有CSS样式应用。

In the above code I am getting only the HTML text but I am not getting CSS and the images in that page. To get the CSS I added another Ajax request. Without this the page loaded in ajax call will not have the css styles applied.

$.ajax({
            url:"conversion_test/to_convert_3264/style.css",
            success:function(data){
                 $("<style></style>").appendTo("head").html(data);
            }
        })

我不知道这是正确的方式去做。现在的问题是,我没有得到Ajax调用过程中的图像。该图片来自 conversion_test / to_convert_3264 /图像文件夹。任何帮助是极大的AP preciated。请让我知道如果我需要提供更多的细节。

I am not sure this is the right way to go about it. The problem is I am not getting the images during the ajax call. The images come from conversion_test/to_convert_3264/images folder. Any help is greatly appreciated. Please let me know If I need to give more details.

在此先感谢。

推荐答案

将它写成这样它有点答案不仅仅是评论跟帖更加明显:

Will write this as an answer so its a bit more obvious than just the comment thread:

的问题是,调用页不位于同一文件夹的页面被调用。目标页面引用图像相对路径,因此,当其插入到调用页面,这些引用不再匹配。换言之,在页面的上下文中已经改变了。

The problem is that the calling page is not located in the same folder as the page being called. The target page references the images with relative paths, and thus when its inserted into the calling page, those references no longer match. In other words, the context of the page has changed.

有两种可能的解决方案:

There are two possible solutions:

  1. 的图像使用绝对路径,这样的背景下并不重要。
  2. 使用jQuery来修复接收HTML的路径(迪利普想出了code这个自己在他的回答)。

这篇关于图像中的HTML页面的jQuery的负载()不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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