Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thijs 97 posts 117 karma points
    Oct 19, 2011 @ 15:15
    Thijs
    0

    Blog4Umbraco show posted comment immediately

    Hi all

    Is there a way that when a visitor posts a comment, the comment is directly added to the page without needing to refresh the page?

     

    Thanks anyway

    Thijs

  • PBrack 20 posts 42 karma points
    Oct 20, 2011 @ 15:29
    PBrack
    0

    1. Force a refresh using javascript

    Pros - takes 30 seconds to do

    Cons - it's still a refresh, looks like a bit of a mess

     

    2. Use javascript to capture the text and input it in on the click event

    Pros - nice and easy to do, looks seamless

    Cons -  you're not catching error, and you're already posting back so it might look messy anyway, clientside data might end up in mismatch with serverside data (bad!)

     

    3. Use AJAX, put the form you're posting back into an async component

    Pros - Does everything you want

    Cons - It's much more work than the other two

     

    The answer here is really to use the Microsoft AJAX framework

  • Thijs 97 posts 117 karma points
    Oct 20, 2011 @ 16:06
    Thijs
    0

    Thank you for the response. I'm going for the javascript way. Here's my code for the people who are interested.

    ///ADD NEW COMMENT TO LIST
    //put data in variables
    var email = jQuery("#commentform #email").val();
    
    var photo = trimPhoto($('#gravatar').css('background-image')); //trimmen want formaat: url("xxxx")
    var website = jQuery("#commentform #url").val();
    var author = '';
    if(website == '')
    {
        author =  jQuery("#commentform #author").val();
    }
    else
    {
        author = '<a href="'+website+'">'+jQuery("#commentform #author").val()+'</a>';
    }
    var comment = jQuery("#commentform #comment").val();
    
    
    $('.commentlist').append(
        '<li class="comment alt highlight" id="new-comment" style="background-color:orange">'+
            '<div class="comment-author vcard">'+
                '<img class="photo avatar-32 photo" width="32" height="32" src="'+photo+'"'+
                '<span class="fn n">'+author+'</span>'+
            '</div>'+
            '<div class="comment-meta">Posted just now!</div>'+
            '<p>'+comment+'</p>'
    );
    $('#new-comment').delay(2000).animate({backgroundColor: '#ffffff'},3000);
    ///END ADD COMMENT TO LIST

    I inputted this code in usercontrols/Blog4Umbraco/AjaxCommentForm.ascx in the submithandler, under the ajax post.

     

    Thijs

  • PBrack 20 posts 42 karma points
    Oct 20, 2011 @ 16:08
    PBrack
    0

    What happens if for some reason the system rejects the comment?  The user will think it has worked...

  • Thijs 97 posts 117 karma points
    Oct 20, 2011 @ 16:16
    Thijs
    0

    If you put it here?

    if(data == 0)
    {
      jQuery("#commentPosted").addClass("error").html( <%= Umlaut.Umb.Blog.BlogLibrary.Dictionary(
         "#CommentFailend","Your comment could not be posted, 
          we're very sorry for the inconvenience") %> ");  
      jQuery("#commentform").show();
      jQuery("#commentform #submit").attr("enabled", true);
    }
    else
    {
      //here
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft