Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Get & display new comments with ajax call

    I've finally managed to implement ajax on my comment submission but, you still have to refresh the page in order to see new comments posted by others and of course that is ugly(when you dont refresh to post a com).
    I've scouted the web and I found a simple solution that I think might do it. The problem is(because Im a newbie and learning on the fly) that I don't know what the guy posted this code means with a thing or 2 :

    Code:
    jQuery.ajax(your_url_to_script, {
        type: 'post',
        data: {
            last: last_comment_time, 
        },
        success: function(data)
        {
            if ( '' != data.content.trim() )
            {
              //code
            }
        }
    });
    Idk what he means by your_url_to script and by last_comment_time and what should I put there in order to make it work.

    I've added a code inside the if statement to get the latest comments and now it looks like this

    Code:
    jQuery.ajax(your_site_to_script, {
      type: 'post',
      data: {
      last: last_comment_time, 
      },
      succes:function(data)
      {
      if( '' !=data.content.trim()) {
    
    var int=self.setInterval(function(){lt_cm()},1000);
    function lt_cm()
      {
      $comment_array = array_reverse(get_comments('post_id'=>8));
      $count = 1;
      if($comment_array){
      comment_number('No comment' ,'1 comment', '% comments');
      foreach($comment_array as $comment) {
      if ($count++ <= 2) {
      comment_excerpt(); }  
      		}
      	}
      else {
      return false;
      }
        }
    	}
    	});
    I am not sure what should I put instead of your_script_to_url and last_comment_time , thanks for any help!
    Last edited by VIPStephan; 06-01-2013 at 03:53 PM. Reason: corrected code BB tags

  • #2
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So reading the jquery.ajax api page I've found out that instead of your_url_to_script should be mypage.php or myscript.js, where

    mypage.php is the page where Im trying to get the latest comments
    or
    myscript.js is the script that's doing the ajax comment posting?

    Off track?

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,476
    Thanks
    6
    Thanked 980 Times in 953 Posts
    Have you read http://api.jquery.com/jQuery.ajax/ ? I think it’s pretty clear that the URL must be the path to a server side script or another HTML document where the data is processed and/or retreived from.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •