gaza165 Posted January 3, 2009 Share Posted January 3, 2009 im trying to write a simple program to retrieve comments from a database using JQuery and ajax.. i am not sure how to correctly pass the data to the ajax to pull back the desired result. this is the code i have so far. js $(document).ready(function(){ $.get("blog_files/getcomments.php",function(data){ alert("Data Loaded: " + data); }); }); then the php it references <?php include("../dbconnect/dbconnect.php"); $blog_id = $_GET['blogid']; $comments = mysql_query("SELECT * FROM blog_comments WHERE blog_id = $blog_id"); $nums = mysql_num_rows($comments); if($nums == 1) { $string = " comment has been "; } else {$string = " comments have been ";} echo "<h2 class='coms'>".$nums.$string." made about '".$title."'</h1>"; while($rows = mysql_fetch_array($comments)) { echo "<div id='comment'>"; echo "<img src='".$rows['comment_pic']."'>"; echo "<div class='cometwrap'>"; echo "<h5>".$rows['name']."</h5>"; echo "<p>".$rows['comments']."</p>"; echo "</div>"; if($_SESSION['login']['username'] == 'admin') { $comment_id = $rows['comment_id']; echo "<div id='delete'>delete</div>"; echo "<input type='hidden' id='commentid' value='".$comment_id."'>"; } echo "</div>"; } echo "</a>"; ?> i need to pass the id of the blog that i am viewing to pull back teh right comments for that particular blog, but i dont know how to pass the id in the javascript. SOMEONE HELP ME!! Link to comment https://forums.phpfreaks.com/topic/139311-need-help-with-jquery-and-ajax/ Share on other sites More sharing options...
RichardRotterdam Posted January 4, 2009 Share Posted January 4, 2009 try this $(document).ready(function(){ $.get("blog_files/getcomments.php", { blogid: 1 } ,function(data){ alert("Data Loaded: " + data); }); }); Link to comment https://forums.phpfreaks.com/topic/139311-need-help-with-jquery-and-ajax/#findComment-729399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.