picwizz Posted March 14, 2013 Share Posted March 14, 2013 (edited) 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 March 14, 2013 by ignace When posting code surround it with code tags Quote Link to comment https://forums.phpfreaks.com/topic/275665-ajax-php-comment-system-not-working-properly/ Share on other sites More sharing options...
ignace Posted March 14, 2013 Share Posted March 14, 2013 (edited) Welcome, please read the forum guidelines before posting. Specifically the section that tells you to surround code with the proper code tags. Nobody wants to read a wall of text. http://www.phpfreaks.com/page/rules-and-terms-of-service#toc_forum_dos Edited March 14, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/275665-ajax-php-comment-system-not-working-properly/#findComment-1418689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.