Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use this code to post comments with ajax on my WP blog. It works fine but I display the comment form on my homepage so the plugin only works for the first post (first comment form).

I want it to work for all the forms.

Here is my code:

if (typeof jQuery != 'undefined') {
    var commentform=$('#commentform');
    commentform.prepend('<div id="comment-status" ></div>');

    var statusdiv=$('#comment-status');

      var formdata=commentform.serialize();

      var formurl=commentform.attr('action');

        type: 'post',
        url: formurl,
        data: formdata,
        error: function(XMLHttpRequest, textStatus, errorThrown){
          statusdiv.html('<p class="wdpajax-error" >You might have left one of the fields blank, or be posting too quickly</p>');
        success: function(data, textStatus){
            statusdiv.html('<p class="ajax-success" >Thanks for your comment. We appreciate your response.</p>');
            statusdiv.html('<p class="ajax-error" >Please wait a while before posting your next comment</p>');

      return false; 
share|improve this question
var commentform=$('#commentform'); - this line seems to be a problem. As ID,s should be unique on a page, You should use class instead, to "plug" into all forms, and then iterate each. –  Marcin Bobowski Feb 15 '13 at 0:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.