Jump to content

ajax php comment system not working properly


picwizz

Recommended Posts

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';
}
?>
Edited by ignace
When posting code surround it with code tags
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.