刷新后加载动态加载页面

时间:2014-04-22 17:31:26

标签: javascript jquery html

我的应用程序中有一些动态加载的html。这是相关的html和jquery代码的片段: main.html中

<div class="row">
    <div class="navbar span2">
        <div class="navbar-inner">
        <ul class="nav nav-pills nav-stacked">
            <li class="active span2" id="statistics">Статистика</li>
            <li class="span2" id="LPU">ЛПУ</li> 
            <li class="span2" id="content">Состав</li>
            <li class="span2" id="add">Добавить</li>
            <li class="span2" id="addParticipant">Участника</li>
            <li class="span2" id="addLPU">ЛПУ</li>
            <li class="span2" id="addAdmin">Администратора</li>
        </ul>
        </div>
    </div>
    <div id="mainContent" class="span9">
    </div>
</div>

的script.js

$(document).ready(function(){
    $("#mainContent").load("statistics.html");
}).on("click","ul.nav-stacked> li", function(){
        if($(this).attr("id")!="add"){
            if($(this).attr("class")!="active"){
                $("ul.nav-stacked li").removeClass("active");
                $(this).addClass("active");
                var contentForLoad=$(this).attr("id")+".html";
                $("#mainContent").load(contentForLoad);
            }
        }
        else{
            if(($(this).attr("class")!="active")&&($("#addParticipant").attr("class")!="active")&&($("#addLPU").attr("class")!="active")){
                $("ul.nav-stacked li").removeClass("active");
                $(this).addClass("active");
                $("#addParticipant").css("opacity","1");
                $("#addLPU").css("opacity","1");
                $("#addAdmin").css("opacity","1");
            }
            else{
                $("ul.nav-stacked li").removeClass("active");
                $("#addParticipant").css("opacity","0");
                $("#addLPU").css("opacity","0");
                $("#addAdmin").css("opacity","0");
            }
        }
});

接下来我点击&#34; .deleteParticipant&#34;按钮我应刷新页面并在#mainContent中加载与加载的内容相同的内容。做我需要的最好的方法是什么?

.on("click", ".deleteParticipant", function() {
    var id={id:$(this).parent().parent().find('td#idOfParticipant').html()};
    $.ajax({
        url:"delete.php",
        type: "POST",
        data: id,
        async: false,
        success: function(data, textStatus, jqXHR)
        {
            console.log(data);
        }
    });
    location.reload();

1 个答案:

答案 0 :(得分:0)

将“history.go(0)”放入您编写的删除按钮中。

<INPUT TYPE="button" onClick="history.go(0)" VALUE="Delete/Refresh">

希望它有助于:)