I am designing a feature on a website where a user clicks "Submit" and it posts a comment into a SQL database with ajax. When the Submit button is pressed, the text "OK" appears next to it if the post is successful. This all works fine, however, when you hit the Submit button a second time, It will say "OK" twice in a row (The first text isn't erased). I can't for the life of me figure out how to erase the text, so that it can only say "OK" once in a row.
Contents of add_comment.php:
Code:
<html>
<head>
<script type="text/javascript">
$(function(){
$(".comment_button").click(function() {
var dataString = $("#content").val();
$("#flash").fadeIn(400).html('Posting comment...');
$.ajax({
type: "POST",
url: "__Ajax-addcomment.php",
data: dataString,
cache: false,
success: function(html){
document.getElementById('content').value='';
$("#flash").after(html);
$("#flash").hide();
}
});
return false;
});
});
</script>
</head>
<body>
<form method="post" name="form" action="" style="padding:0px; margin:0px;">
<textarea name="content" id="content" style="width:600px; height:114px; font-family:Verdana,Arial,Tahoma,Times New Roman; font-size:12px; border:1px #666 solid;" onFocus="this.value=''; this.onfocus=null;">Enter your comment...</textarea><br />
<input type="submit" value="Post Comment" id="v" name="submit" class="comment_button"/> <span id="flash"></span>
</form>
</body>
</html>
Contents of __Ajax-addcomment.php:
Code:
<?php
$count = 0;
// just says OK for now... this is a stub
echo 'OK';
?>
Somebody please help, I imagine it is something simple, I am new with jQuery and learning. Thank you.