Edit: Originally I had a simple form Ajax script that wasn't working, turns out it was an extra bracket somewhere.
I have changed my question to the following:
1.)What I'd like to know is that how can I create an extra div to appear every time a value is sent? Of course, without changing the whole content inside the container and also preserving previous divs that were already created by the same mechanism.
2.)I'm going to cleanse input on the server. What would I echo server-side? Just the sanitized data or the sanitized data inside a div aka <div>$sanitizeddata</div>
?
Scroll to see the html visual of what I mean.
Note: I didn't want to start another question with the same code so I just edited my question accordingly after figuring out what was wrong with it. (My apologies to the previous repliers, but no one seemed to have caught the error! :P)
<script type="text/javascript">
$(document).ready(function()
{
$("#testform").submit(function(e)
{
$.post("1.php", $(this).serialize(),function(data)
{
$('.result').html(data);});
e.preventDefault();
});
});
</script>
<div id="container" class="result">
<div><p>Some content 1</p></div>
<div><p>Some content 2</p></div>
<div><p>Some content 3</p></div>
//A new DIV is created with callback data (sanitized input) every time something is submitted
by the form.
<div></div>
//A new DIV is created with callback data (sanitized input) every time something is
submitted by the form while preserving previous DIVs already created by Javascript.
<div></div>
<div>
<form id="testform" action="1.php" method="post">
Number: <input type="text" name="num" />
<input type="submit" value="Submit Comment" />
</form>
</div>
</div>