繁体   English   中英

Ajax替换整个页面,而不仅仅是div

[英]Ajax replacing entire page, not just the div

我有一个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;
    });
});

HTML

<div id="contents" style="height:1200px; width: 620px">
    <!-- all html here that should be replaced-->
</div>

你为什么不用$ .load()?

$(function () {
    $('#gnav a').click(function (e) {
        e.preventDefault();
        $('#contents').load(this.hash.substr(1) +'.php')
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM