我有一个带有Ajax调用的页面,它应该替换内容div。但是,当单击链接时,整个页面将替换为内容div,而不是仅替换它应该使用的文本。有什么想法吗?
$(document).ready(function () {
$('#gnav a').click(function () {
var page = this.hash.substr(1);
$('#contents').html("");
$('#content_wrapper').block();
$.get(page +'.php', function(gotHtml){
$('#contents').html(gotHtml);
$('#content_wrapper').unblock();
});
return false;
});
});
<div id="contents" style="height:1200px; width: 620px">
<!-- all html here that should be replaced-->
</div>
答案 0 :(得分:2)
为什么不使用$ .load()?
$(function () {
$('#gnav a').click(function (e) {
e.preventDefault();
$('#contents').load(this.hash.substr(1) +'.php')
});
});