pyblosxom ajax comments

This patch was applied to the Pyblosxom contributed plugins pack in revision 973. It’s included in version 1.3.3 of the contrib pack.

For the impatient:
  Download contrib pack 1.3.3 (includes AJAX support)
  PyBlosxom home page
  PyBlosxom plugin registry

PyBlosxom, the server software that runs this site, uses a plugin to handle commenting. This patch adds AJAX support to that plugin. Try it!

Specifically, comment previewing and posting can optionally use AJAX, as opposed to full HTTP POST requests. This avoids a full-size roundtrip and re-render, so commenting feels faster and more lightweight.

To enable AJAX comments, set the comment_ajax config parameter in config.py to True.

AJAX commenting degrades gracefully in older browsers. If JavaScript is disabled or not supported in the user’s browser, or if it doesn’t support XmlHttpRequest, comment posting and preview will use normal HTTP POST. Feel free to check out the JavaScript.

Also, since the browser window never sends a full POST request, refreshing the page after a preview or comment submission won’t re-post the comment, or pop up an annoying “are you sure?” dialog box.

AJAX comment support requires a few elements in the comment-form flavour template. Specifically, the comment-anchor tag must be the first thing in the template:

<a name="comment-anchor" id="comment-anchor"></a>

Also, the buttons in the comment form should include these onsubmit and onclick attributes:

<form name="comments_form" ... onsubmit="return false;">
  <input value="Preview" name="preview" type="submit"
         onclick="send_comment('preview');" />
  <input value="Submit" name="submit" type="submit"
         onclick="send_comment('post');" />

Finally, this script tag must be included somewhere after the </form> tag:

<script type="text/javascript" src="/comments.js"></script>

All of these tags are included in the default comment-form template that comes with this plugin.

AJAX comment support is copyright 2006 Ryan Barrett, and is distributed under the GPL. Thanks to Todd Warner and Blake Winton for beta testing and improvements.

See also:

112 Comments

  1. Nick Moffitt
    9/3/2006 #

    Hmm, this does look cool.

  2. 9/3/2006 #

    Whoah, looks cool. I’d never dream that pyblosxom would even get AJAX.

    And the previewing, OMG, faints

  3. 9/5/2006 #

    So fresh and so clean!

  4. 9/5/2006 #

    just checking out the ajax gadget…:)

  5. 9/6/2006 #

    sdfsdfs

  6. 9/13/2006 #

    Testing this Ajax comment thingy.

    Pretty.

  7. 9/13/2006 #

    Argh!

    OK. I figured out how to make the “Post a comment…” / form disappearing act to work (a simple “display: none;” in a CSS file), but the actual Ajax innerHTML stuff is not working for me. Any intention to write up a more elaborate HOWTO on all the little cool bits?

    I may be missing something very simple, but reading through the code 500 times… I don’t see where I am going wrong… Is there supposed to be a <div id=”warning”></div> and <div id=”comment-preview”></div> somewhere? The latter seems to be unneccessary, but… I don’t know. I am left scratching my head.

    This is cool stuff that I have not played with until now. I would love to see your response.

    -todd

  8. 9/18/2006 #

    This is a test of the ajax comments.

  9. 9/18/2006 #

    hi todd! i have to admit, i’m not a pyblosxom export or an AJAX expert, so i can’t say i plan to write anything more in-depth than this page.

    i learned most of the AJAX stuff from tutorials and references on w3schools and javascript. the only unusual pyblosxom parts were 1) adding a cb_handle() callback to serve comments.js and 2) using a new renderer to only serve the comment div for AJAX requests.

    as for getting AJAX comments working on your site…ah, i think i see the problem. the script tag in your comment-form template should have src="/comments.js", not src="/plugins/comments.js". comments.py is hard-coded to serve it from the /comments.js URL.

    granted, this is an ugly hack. i’d love to see something like filekicker integrated into pyblosxom, to make it easier to serve helper files like this.

  10. Alvaro
    9/19/2006 #

    Its great

  11. 9/19/2006 #

    Ryan,

    That directory location (/plugins/comments.js) was one of the location attempts I made. I moved it back to /comments.js – at first.

    I put some debug info into the js file (I can’t see the http log file to see if they are being picked up). Found out that the comments.js file is not being found. I copied comments.js to every directory I have access to… no dice. So, I had to use the full URL in the HTML. To make both pyblosxom/comments.py and the html happy there is now a copy of comments.js in:
    1. plugins/
    2. a browsable location

    So… things started to work to an extent. One can see an attempt to insert the ajaxed data above comment-anchor. But, it looks like no form data is picked up after that req.send(post_data). The xml_http_request.responseText remains empty. If you have any incite, lemme know. Otherwise, so far, this is pretty educational.

    Once I get everything working, I will make a nifty writeup about it and see if anything needs to be improved.

  12. 9/20/2006 #

    argh. sorry for the trouble, todd.

    i see what you mean about comments.js. it is supposed to be in the plugins/ dir, but comments.py can only serve it if pyblosxom handles requests for the /comments.js URL. on your site, it doesn’t, so pyblosxom won’t serve it regardless of which directory it’s in. i should make that configurable.

    as for the missing response, i’m not sure. :/ try setting py['log_level'] = 'info' in  config.py, then check for “AJAX request: …” log messages to see if pyblosxom is correctly rendering the response.

  13. 9/21/2006 #

    Yeah, I have a copy of comment.js in the plugins/ directory and one in a browsable place for the HTML.

    Got comment previewing to work. I just had to clear out my cache. Seems javascript is cached a bit differently than the HTML. Odd. Anyway, I cleared out my cache and previewing suddenly worked.

    Posting is all that remains failing. I think there is a definite disconnect somewhere. I see the AJAX request object generated, but by the time we get to comment_statechange(…) the xml_http_request.responseText is an empty string. Not sure why. Still investigating.

    Nicely filling up your comment directory aren’t I. ;)

  14. 9/21/2006 #

    Fixed! Thanks Ryan!

    For those following this comment thread, in short, the magicword plugin will break this ajax code in quiet mysterious ways. You can have the magicword plugin merely loaded, but not in use, and it will break it. There is a bit of extra work to do to get magicword working with the ajax stuff.

    …if you are not using magicword, read no further…

    More or less, you need to do 2 things:
    (1) add this line to the comments.js code right near where all the other post_data plus= stuff is (note my plus sign keeps getting escaped):

    post_data plus= ‘&magicword=’ plus document.getElementById(‘comment-magicword’).value;

    (2) In your HTML, make sure you add “id=’comment-magicword’” to the magicword <input> element.

    That’s it, it should all just work.

  15. adasddas
    10/4/2006 #

    sdasdaasd

  16. 10/4/2006 #

    since todd’s last post, i’ve updated the
    javascript so that it submits the entire form. along with other benefits, this means anti-comment-spam plugins will work out of the box. no workaround needed!

    i’ve also incorporated a couple of todd’s additions, including better error reporting. thanks, todd!

  17. sdfdsfsd
    10/25/2006 #

    fdsfsdfd

  18. 10/27/2006 #

    dffdfd

  19. 10/29/2006 #

    %u9519%u8BEF%u4FE1%u606F%u9519%u8BEF%u4FE1%u606F%u9519%u8BEF%u4FE1%u606F%u9519%u8BEF%u4FE1%u606F%u9519%u8BEF%u4FE1%u606F

  20. name
    11/9/2006 #

    Test

  21. s
    11/12/2006 #

    as

  22. kk
    11/12/2006 #

    k

  23. Cool
    11/13/2006 #

    Coooool!

  24. dfsdf
    11/13/2006 #

    sdfdsf

  25. <font color=red>Red</font>
    11/13/2006 #

    <b><font color=green>Bold</font>/b>

  26. %u05D2%u05D3%u05DB%u05D3%u05D2%u05DB
    11/13/2006 #

    %u05DB%u05D3%u05D2%u05DB%u05D3%u05D2%u05DB%u05D3%u05D2%u05DB

  27. blah
    11/18/2006 #

    neat

  28. 11/20/2006 #

    This is a test of the comments

  29. m
    11/22/2006 #

    Test

  30. 11/27/2006 #

    jgvouhvoyh

  31. 11/28/2006 #

    testing

  32. iii
    11/30/2006 #

    kkk

  33. joe
    12/1/2006 #

    nice

  34. 12/3/2006 #

    Awesome

  35. 12/4/2006 #

    dasdsadsa

  36. michael
    12/9/2006 #

    test

  37. s
    12/9/2006 #

    d

  38. 12/11/2006 #

    Realy nice!

  39. What
    12/12/2006 #

    est

  40. paige
    12/17/2006 #

    cool!!

  41. 12/18/2006 #

    dom

  42. rob
    12/29/2006 #

    great work!

  43. a designer
    12/29/2006 #

    mmm

  44. test
    1/11/2007 #

    test

  45. 1/12/2007 #

    ruyturuy

  46. Lock Picking Guide
    1/19/2007 #

    Great, going to implement on my site soon!

  47. rewww
    1/24/2007 #

    ererewrwe

  48. 1/26/2007 #

    testing

  49. Peej
    1/27/2007 #

    Yes – I like berry berry maach!

  50. 2/4/2007 #

    Good one. Like it. :)

  51. gfgffg
    2/12/2007 #

    gfgg

  52. 2/15/2007 #

    cool tool will be implementing it with my sites!!!

  53. 2/15/2007 #

    asd

  54. Gordon
    2/17/2007 #

    Gecko

  55. 2/20/2007 #

    thank u :)

  56. oldman
    2/21/2007 #

    wow

  57. 3/13/2007 #

    test

  58. 3/13/2007 #

    neat

  59. 3/14/2007 #

    GROVEY

  60. 3/14/2007 #

    AJAX IS MY friend

  61. 3/18/2007 #

    kkk

  62. tetst
    3/25/2007 #

    alright

  63. robin
    5/30/2007 #

    test

  64. 7/29/2007 #

    test

  65. 8/10/2007 #

    blah

  66. yeah
    8/11/2007 #

    that is definitely cool!

  67. roger
    8/18/2007 #

    testing

  68. testsan
    9/10/2007 #

    123 etst 456

  69. testatre
    9/23/2007 #

    Description: Regardless of what you do using Ajax, they all rely on the same basic functions. This is a very small Ajax routine (less than 3 Kb) that enables you to easily use Ajax on your site to send “GET” or “POST” requests asynchronously. Some examples include getting the contents of an external HTML file, getting the contents of a XML file and return it as a DOM object, and sending information via PoST to a receiving PHP script (with the information being from either a form or any element on the page). It’s easier than you think with the help of this routine! Here’s a quick listing of the public variables and methods exposed by this routine:

  70. 9/24/2007 #

    asdas

  71. 9/25/2007 #

    asdas

  72. 10/12/2007 #

    test

  73. test
    10/17/2007 #

    test

  74. 10/17/2007 #

    testing 1234

  75. 11/9/2007 #

    dfgdfgdfgdfg

  76. 11/17/2007 #

    Just checking. Bye

  77. SimonRaven
    11/18/2007 #

    meh. actual posting isn’t working. serving the js file out of a subdir, will try modding it to look where i stuck it. i did notice, however, that you have the plugin looking elsewhere is it doesn’t find the script at root (/).

    not sure what exactly could be wrong. i get the preview, but not the actual post, i get “Empty response from server.”

  78. 11/27/2007 #

    Here is good tutorial for AJAX
    Ajax Tutorial
    go to Ajax link

  79. 12/5/2007 #

    Testing…

  80. 2/1/2008 #

    I hate spam.
    Let the scum die and rot in the guts of the outernets.

  81. 2/19/2008 #

    erfg

  82. 2/22/2008 #

    tyrt

  83. 2/26/2008 #

    tryjrtjrty

  84. 2/26/2008 #

    hahaha

  85. 2/26/2008 #

    <script type=”text/javascript”>alert(“haha”);</script>

  86. 2/26/2008 #

    XSS on preview!

  87. 2/26/2008 #

    with the script code above? looks like preview sanitizes it correctly. mind explaining a little more?

    btw, if the XSS is only on preview, which would only be shown to the attacker themself, it doesn’t seem like there’s any threat.

  88. 3/1/2008 #

    assasdaadsaasassda

  89. 3/1/2008 #

    aasdasdsadsadsaasdas

  90. asdfasdf
    3/4/2008 #

    asdf

  91. 3/9/2008 #

    This is a test

  92. aaa
    3/13/2008 #

    aaa

  93. Robert
    3/16/2008 #

    Testing, pretty cool.

  94. 3/24/2008 #

    asdasd

  95. 3/29/2008 #

    helloz

  96. 3/29/2008 #

    testing

  97. Test
    4/2/2008 #

    Dies ist ein Testeintrag =)

  98. das ist ein test
    4/27/2008 #

    test

  99. Steve
    5/3/2008 #

    test

  100. dajul
    6/16/2008 #

    I have this plugin working with pyblosxom.cgi, but I can’t figure out how to make it work with static pages (rendering site with pyblcmd)

    Any advice? Thanks

  101. dajul
    6/16/2008 #

    Ops, sorry… I forget: with static pages, when I preview or submit comments, all site is re-drawn inside the place where comments are supposed to be. After that, none comments are saved.

  102. dajul
    6/22/2008 #

    Finally, I did a RewriteRule on my hosting to clean cgi “ugly” URL :P
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteRule  ^blog?(.*)$  /cgi-bin/pyblosxom.cgi$1  [last]
    </ifModule>

  103. Test
    8/14/2008 #

    Very nice

  104. 9/27/2008 #

    test

  105. 10/23/2008 #

    dfasdfasdfasdf

  106. 11/30/2008 #

    test  test  test

  107. 1/3/2009 #

    !

  108. teste
    2/12/2009 #

    testing!

  109. 3/8/2009 #

    Previewing works fine. However, posting gives me the following message: A software error occurred. Please contact the administrator.

  110. just a test
    8/11/2009 #

    another test

  111. 8/26/2009 #

    asd asd asd asd asd asd

  112. 5/31/2010 #

    There only few good resources for Ajax beginners. I now only php tutorial and w3schools

Post a Comment

Post a comment...

Your email is never published nor shared.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


  • home
    about
    pictures
    software
    index
    feed