Chris,
You can do one of two things: 1) When the form is submitted return the new comment. In other words, when the new comment is posted, return what you would return from your newcomments.php script. If you do that, your javascript would look something like this: $(document).ready(function() { $('#myForm').ajaxForm(function(newcomment) { $('#thankyou').show('slow'); $('#newcomment').hide('fast'); $('#comments h1').after(newcomment); }); }); Note that the callback function is passed the server response so if your comment.php script returns the new comment everything will fall nicely into place. This would be my preferred method since it requires only a single round trip to the server. 2) You can use $.get like you're attempting to do now, but you need to handle the response. Your $.get call is working, you're just not doing anything with the response. Try something like this: $(document).ready(function() { $('#myForm').ajaxForm(function() { $('#thankyou').show('slow'); $('#newcomment').hide('fast'); $.get('newcomments.php', function(newcomment) { $('#comments h1').after(newcomment); }); }); }); Again, note that the callback is passed the server response (the new comment). Hope this helps! Mike On 7/16/07, Chris <[EMAIL PROTECTED]> wrote:
Thank you for the help mike, I really appreciate it! Try making a comment on our blog. http://www.iphoneappr.com/index.php?post=55 I am trying to make it so that the comment, once submitted, shows up in the list of comments. Thank you! On Jul 16, 3:22 pm, "Mike Alsup" <[EMAIL PROTECTED]> wrote: > Chris, > > Can you put together a simplified example page. I feel like I'm only > getting part of the picture. > > Mike > > On 7/16/07, Chris <[EMAIL PROTECTED]> wrote: > > > > > Any ideas? > > > On Jul 15, 12:07 pm, Chris <[EMAIL PROTECTED]> wrote: > > > Thank you for the reply mike! I added this to my script: > > > $(document).ready(function() { > > > // bind 'myForm' and provide a simple callback function > > > $('#myForm').ajaxForm(function() { > > > $('#thankyou').show('slow'); > > > $('#newcomment').hide('fast'); > > > $('#newestcomment').show('slow'); > > > > }); > > > }); > > > > and did this with the div: > > > <div id="newestcomment" style="display:none;"> > > > <a href="#"><? echo $_POST["name"]; ?></a><? echo $_POST["comment"]; ? > > > > </div> > > > It did not seem to pull the data from post, but it does add another > > > space for a comment. The way my form is processed is it send the post > > > info to comment.php and that adds it to the database. How do i have > > > the jquery talk to the php. I tried using a get from an external php > > > page that pulls the latest comment from the database but I didn't know > > > where to go after that. > > > Thank you! > > > -Chris > > > > On Jul 15, 6:06 am, "Mike Alsup" <[EMAIL PROTECTED]> wrote: > > > > > Sorry, I'm meant the formatted *comment*. When a comment is posted, > > > > return something like this from the server (filling in the correct > > > > info as appropriate): > > > > > <div class="oddcomment"> > > > > <p><a href="#">author name here</a></p><p>Comment text here</p> > > > > </div> > > > > > Mike > > > > > On 7/15/07, Chris <[EMAIL PROTECTED]> wrote: > > > > > > Thank you for the reply mike, > > > > > Unfortunately I don't understand how I could use this? What is the > > > > > formatted column? I think i understand that you would be running this > > > > > code $('#comments h1') after the (data) for the form is complete. > > > > > > On Jul 13, 4:17 am, "Mike Alsup" <[EMAIL PROTECTED]> wrote: > > > > > > Chris, > > > > > > > Why don't you return the formatted column when it is posted. Then you > > > > > > could do something like this: > > > > > > > $(document).ready(function() { > > > > > > $('#myForm').ajaxForm(function(data) { > > > > > > $('#thankyou').show('slow'); > > > > > > $('newcomment').hide(); > > > > > > $('#comments h1').after(data); > > > > > > }); > > > > > > > }); > > > > > > > Mike > > > > > > > On 7/13/07, Chris <[EMAIL PROTECTED]> wrote: > > > > > > > > Hello everyone, > > > > > > > I'm a bit of a noob to this whole AJAX thing so you'll have to forgive > > > > > > > me. I've setup a blog, using jQuery the comments are added to mysql > > > > > > > using this form plugin (http://www.malsup.com/jquery/form/#getting- > > > > > > > started). Posting the comments work great, I was even able to add in > > > > > > > a confirmation saying "Thank you for posting". My dilemma is showing > > > > > > > the new comment on the page without refreshing. Here is the page to > > > > > > > test it: (http://www.iphoneappr.com/index.php?post=48). I was > > > > > > > thinking I could do a $.get to an external php page that queries > > > > > > > mysql with the most current post and put it in a specific div on the > > > > > > > page. > > > > > > > Here is the function for the form. > > > > > > > > <script type="text/javascript"> > > > > > > > // wait for the DOM to be loaded > > > > > > > $(document).ready(function() { > > > > > > > // bind 'myForm' and provide a simple callback function > > > > > > > $('#myForm').ajaxForm(function() { > > > > > > > $('#thankyou').show('slow'); > > > > > > > $('#newcomment').hide('fast'); > > > > > > > > }); > > > > > > > }); > > > > > > > > </script> > > > > > > > > Thank you for any help! This is driving me nuts!!!!!