Search the Community
Showing results for tags 'ajax php'.
-
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'; } ?>
-
I have been stuck on this for 3 days... I would love the experts to shoot me some words of advice, appreciate it. I have a form I create from a while loop in php. I can submit it if I name the form and place that in the AJAX but it just uploads the last record in the table not the one I actually click. I know I need a unique ID from the form, which I have but I can get it in the AJAX ;( I have used $(this).attr("id") , $(this).form("id") etc and nothing gets it in.. Any advice would be great MY PHP Loop while($row = mysql_fetch_array($pendingresult)) { $id = "myForm".$row['reg_id']; echo '<table width="100%" border="0" cellspacing="0" cellpadding="0" >'; print "<form id=\"$id\" name=\"CDs\" method=\"post\" >"; echo '<tr class="commentContainer" style="color:#FFF">'; echo"<td><input type=\"text\" name=\"team_name\" value=\"$row[team_name]\"</td>"; echo"<td><input type=\"text\" name=\"reg_id\" value=\"$id\"</td>"; echo"<td><input type=\"text\" name=\"team_level\" value=\"$row[team_level]\"</td>"; echo"<td><input type=\"text\" name=\"notes\" value=\"$row[comments]\"</td>"; echo"<td>"; echo "<td class=\"delete\" align=\"center\" id=".$row['reg_id']." width=\"10\"><a href=\"#\" id=\"$row[reg_id]\"><img src=\"admin/images/delete.png\" border=\"0\" ></a></td>"; echo "<td class=\"approve\" align=\"center\" id=".$id." width=\"10\"><a href=\"#\" ><img src=\"admin/images/approve.png\" border=\"0\" ></a></td>"; echo "</td>"; echo"</tr>"; echo "</form>"; echo ' </table>'; } My AJAX <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { <!--$('#load').hide();--> }); $(function() { $(".approve").click(function() { var commentContainer = $(this).parent('tr:first'); var id = $(this).attr("id"); var string = 'id='+ id; var formData = $(this).attr("id") $.ajax({ type: "POST", url: "approve.php", data: $(formData).serialize(), cache: false, success: function(){ commentContainer.slideUp('slow', function() {$(this).remove();}); } }); return false; }); }); </script>