用jquery重新加载div

时间:2016-03-16 17:23:54

标签: javascript jquery html

我有一个php文件,其中包含一个带有id= containerbox的div元素。

 <div id=containerbox>
     <button id="buttonme" type="button">click me</button>
    </div>
    <script>

       $("#buttonme").click(function(){

        jQuery.ajax({
            type: 'POST',
            url: 'testone.php',
            success: function (data) {
                response = jQuery.parseJSON(data);
                if (response.status == 'error') {
                    erroroccur(response);
                }
            }
        });


})


        function erroccur(abc) {
            alert(error);
            //here i want something that only Refreshes/Reloads the containerbox
        }

    </script>

testone.php

<?php

//...something
$response=Array(
"status"=>'error'
);
return json_encode($response);
?>

它包含一个进行ajax调用的函数,并根据收到的响应决定它是否是一个错误。每当它收到响应中的错误时它会触发一个需要显示警告框并重置Div元素的函数当我第一次来到那个页面的时候。这可以实现吗?

注意:我知道什么都不会改变,但为了简单起见,我使用了这个例子

1 个答案:

答案 0 :(得分:0)

怎么样:

// keep a reference to the initial html in your div
var initialState = $("#containerbox").html()

/* ... */
function erroccur(abc) {
    alert(error);
    // revert the div content to its initial state
    $("#containerbox").html(initialState)
}
相关问题