2012-03-25 150 views
1

我用jQuery加載一個頁面是這樣的:圖像不加載,jQuery的

$('#container').load('books/book1/inleiding.php'); 

然而,圖像是,圖書/ BOOK1 /圖像所以inleiding.php它只是圖像/ someImage.jpg

當我加載頁面,然後圖像的鏈接保持不變,因此不起作用。

我也試過:

$.get('books/book1/inleiding.php', function(data) { 
    $('#container').html(data); 
    alert('Load was performed.'); 
}); 

但這有同樣的問題,有沒有一個簡單的解決方法?

+0

你說的加載圖像是什麼意思?你是否僅僅使用php的img標籤迴應html代碼?也分享你的PHP代碼。 – slash197 2012-03-25 11:38:05

+0

是的,使用絕對URL-s爲您的圖像 – 2012-03-25 11:38:24

回答

2

圖像應直接鏈接到url或服務器根目錄。
如果圖像是在books/book1/images/...然後鏈接到books/book1/images/...

也許你可以嘗試改變與SRC:

$.get('books/book1/inleiding.php', function(data) { 
    $('#container').html(data); 
    $('#container img').each(function(){ 
     $(this).attr('src', 'books/book1/'+$(this).attr('src')); 
    }); 
    //alert('Load was performed.'); 
}); 
+0

工作偉大,謝謝 – clankill3r 2012-03-25 12:59:01