Image not loaded in jQuery load() of a HTML page

邮差的信 提交于 2019-12-06 02:28:42
Miika L.

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. Use absolute paths for the images so that the context doesn't matter.
  2. Use jQuery to fix the paths in the received html (Dilip came up with the code for this himself in his answer).

I finally fixed based on the @MiikaL suggestion. Following is my code to solve the problem.

function replaceImageSource() {
       $("img").each( function(){
              $(this).attr({
                 src: 'conversion_test/to_convert_3264/' + $(this).attr('src')
              });
            });
    }

Hope this helps some one. Thanks for all your help.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!