2012-06-27 52 views
2
$('#cart').load('shop.php/ #cart'); 

所以我想重裝我的網頁的車款,但它加載它原來的DIV ID裏面,像這樣:jQuery的負載頁面片段加載雙div編號

<div id="cart"> 
    <div id="cart"> 
     // everything loaded fine here 
    </div> 
</div> 

我只是希望它顯示一個div,我做錯了什麼?

+0

嘗試'$('#cart')。load('shop.php /');'。 –

回答

5

你一切正確。然而,loading of page fragments在jQuery的工作原理如下:

$('#result').load('ajax/test.html #container'); 

當這種方法執行,它將檢索的內容AJAX/test.html的, 但隨後的jQuery解析返回的文檔找到與 元素容器的ID。該元素及其內容將 插入到具有結果ID的元素中,並且檢索到的其餘文檔將被丟棄。

所以它也包括容器。要包含內部內容,請使用以下內容:

$("#cart").load("shop.php/ #cart > *");​​​​​​​​​​​