請有人可以告訴我如何從另一個頁面上使用jQuery ajax()方法從另一個頁面中提取內容?如何使用JQuery ajax()加載HTML片段?
anotherpage.html
<html>
<head></head>
<body>
<div id="content">I want to extract this element</div>
</body>
</html>
我已經試過:
$.ajax({
url: "anotherpage.html #content",
dataType: "html"
}).done(function(data){
$("#results").html(data);
})
但它返回完整的頁面,而不僅僅是#內容片段。
注意:我知道如何使用load()函數來簡化它,但我想知道如何使用ajax()方法實現它。
在此先感謝。
可能重複http://stackoverflow.com/questions/2398568/loading-page-framents-with-jquery-ajax –