Ajax comments doesn't work after view ajax block load but work after page load.

Created on 17 March 2021, about 4 years ago
Updated 6 May 2025, about 1 month ago

I loaded a views using ajax custom code $.ajax({'url': Drupal.url('views/ajax'), 'type': 'POST', 'cache': 'false', 'data': { 'view_name': 'views_name','view_display_id': 'page_1','view_args': groupId}. This views uses ajax comment, after ajax call ajax comment is not working. After one page load, ajax comment start working.

🐛 Bug report
Status

Active

Component

Code

Created by

🇮🇳India devendra mishra Noida

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The reason AJAX Comments stops working after loading a view via custom AJAX in Drupal is that the necessary JavaScript behaviors aren't automatically re-attached to the new content. To fix this, within the success callback of your $.ajax() call, after injecting the new view content into the DOM, cat language translator you need to explicitly call Drupal.attachBehaviors() and pass it the container element of the loaded view. This will re-initialize the JavaScript behaviors, including those for AJAX Comments, making them functional without a full page reload. Ensure you correctly identify the container element and handle the Views AJAX response structure appropriately.

Production build 0.71.5 2024