-1

I have a php file which contains a div element with 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>

testone.php

<?php

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

it contains one function which makes an ajax call and depending on the response recieved it decides if it is an error.Whenever it recieves an error in the response it fires a function which need to show an alert box and reset the Div element to the way it was when i first came to that page.Can this be achieved?

Note: I know nothing will change there but just for the sake of simplicity i have used this example

Nahid Suhail
  • 185
  • 2
  • 2
  • 10
  • 1
    Nothing in your code *changes* `containerbox` - it will always be exactly as it was before the ajax call – Jamiec Mar 16 '16 at 17:27
  • 1
    http://stackoverflow.com/questions/5557641/how-can-i-reset-div-to-its-original-state-after-it-has-been-modified-by-java – sachin k Mar 16 '16 at 17:28
  • @Jamiec for the sake of simplicity i have shown the button part.I know nothing willl change – Nahid Suhail Mar 16 '16 at 17:28
  • For the sake of not wasting time trying to work out what you're doing, you should post the specific details. – Jamiec Mar 16 '16 at 17:29
  • @NahidSuhail: If you question is literally "Can this be done?" then the answer is simply "Yes". The question is, *have you tried*? Where are you stuck? – David Mar 16 '16 at 17:30
  • i have a very large module .I just gave an overlay of what has to be achieved there .It is just the same as it is here .I need to refresh one div present at the page – Nahid Suhail Mar 16 '16 at 17:30
  • @David yes i tried this using `.load()` method again but instead of passing the url of the page i passed the url of div.Found that in one of answers in stack overflow. – Nahid Suhail Mar 16 '16 at 17:33
  • @NahidSuhail: Nobody here can help you understand why that attempt didn't work if you don't provide any information about it. Currently this question contains *no code* which attempts to update anything on the page. Which would explain why nothing on the page is being updated. – David Mar 16 '16 at 17:35

1 Answers1

0

What about :

// 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)
}
cl3m
  • 2,791
  • 19
  • 21