HI all. Iv made this ajax comment system it works but not properly. When you first use it, it works but when you add a second post it doesnt show until i refresh the page. So how to i make this work properly, so you can keep commenting more that one post without refreshing. Thanks in advance
here is the jquery
function postDash(){
var details = $('#postdetails').val();
var pu = $('#profileuser').val();
var dataString = 'details='+ details + '&pu='+ pu;
if(details == "" || pu == ""){
$('.postmessage').html("Write something then!");
} else {
$('.postmessage').html("Posting now...");
$.ajax({
type: "POST",
url: "inc/profilepost.php",
data: dataString,
cache: false,
success: function(data){
$('.postmessage').hide();
$('#eachpostcon').html(data);
}
});
}
return false;
}
here is the profilepost.php script
<?php
include_once("func.php");
if($_POST){
$details = $_POST['details'];
$pu = $_POST['pu'];
mysql_query("INSERT INTO propost (details, pu, su, date)
VALUES('$details','$pu','$session_rand', now())") or die (mysql_error());
} else {
echo 'No!';
}
?>
<div id="conbb">
<div id="coneach"><?php echo $details; ?></div>
</div>
here is the html
<div id="coneach">
<form action="" method="post" onsubmit="return false;">
<textarea rows="3" id="postdetails" placeholder="Post to dashboard" class="dashboardform"></textarea>
<input type="hidden" id="profileuser" value="<?php echo $id; ?>" />
<div class="spandbtn"><input type="submit" value="Post!" onclick="postDash()" /></div>
<div class="spandmess"><span class="postmessage"></a></div>
<div class="clear"></div>
</form>
</div>
</div>
<div id="eachpostcon">
</div>
<?php
$getposts = mysql_query("SELECT * FROM propost WHERE pu='$id' ORDER BY date DESC");
$countposts = mysql_num_rows($getposts);
if($countposts > 0){
while($row = mysql_fetch_array($getposts)){
$pdet = $row['details'];
$date = $row['date'];
echo '
<div id="conbb">
<div id="coneach">' .$pdet. '</div>
</div>';
}
} else {
echo 'No Posts yet';
}
?>