G
G
Genri_Rus2020-05-29 17:55:54
WordPress
Genri_Rus, 2020-05-29 17:55:54

How can I display the comment form on button click?

In general, I need to display the comment form by clicking on the button, an example like this: vintagetechnics.ru/comment

I tried to implement it this way, but nothing is displayed:

$(document).on("click", '#comment .add-btn', function(e) {
    e.preventDefault();
    
    var data = {
      action: 'comment_form',
    }
    
    $.ajax({
      type: "POST",
      url: comment_reviews_form.ajax_url,
      data: data,
      dataType: 'json',
      success: function(data) {
        console.log(data);
        if (data.success) {
          console.log(data);
        }
      },
      error: function(xhr) {
        
      }
    });
    
    return false;
  });

add_action( 'wp_ajax_comment_form', 'vintage_technics_comment_form' );
add_action( 'wp_ajax_nopriv_comment_form', 'vintage_technics_comment_form' );

function vintage_technics_comment_form() {
  wp_send_json_success(  comments_template() );
}


When I click on the button, I have 0 in the console, what could be the reason, or with the ajax option, the comment form cannot be displayed at all?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question