Javascript 使用jquery重新加载div

Javascript 使用jquery重新加载div,javascript,jquery,html,Javascript,Jquery,Html,我有一个php文件,其中包含一个div元素,id=containerbox <div id=containerbox> <button id="buttonme" type="button">click me</button> </div> <script> $("#buttonme").click(function(){ jQuery.ajax({

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

 <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>

点击我
$(“#按钮ME”)。单击(函数(){
jQuery.ajax({
键入:“POST”,
url:'testone.php',
成功:功能(数据){
response=jQuery.parseJSON(数据);
如果(response.status==“error”){
错误发生(响应);
}
}
});
})
功能错误(abc){
警报(错误);
//在这里,我想要只刷新/重新加载containerbox的东西
}
testone.php

<?php

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

它包含一个函数,用于进行ajax调用,并根据收到的响应决定是否为错误。每当它在响应中收到错误时,就会触发一个函数,该函数需要显示一个警报框,并将Div元素重置为我第一次访问该页面时的状态。这可以实现吗

注意:我知道这里不会有任何变化,但为了简单起见,我使用了这个示例

关于:

// 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)
}

代码中没有任何更改
containerbox
——它将始终与ajax之前完全相同call@Jamiec为了简单起见,我已经展示了按钮部分。我知道没有什么会改变,为了不浪费时间去弄清楚你在做什么,你应该发布具体的细节。@NahidSuhail:如果你的问题是“这能做到吗?”那么答案就是“是”。问题是,你试过了吗?你被困在哪里?