Failed to get data in JS, found this question
For AJAX returns, jQuery returns events likes
$(document).ready ->
$("#new_message").on("ajax:success", (e, data, status, xhr) ->
console.log(xhr);
).on "ajax:error", (e, xhr, status, error) ->
console.log(xhr);
However, as shown in the Rails Guide, Rails-ujs returns only one parameter event
with all other in detail
attribute. So the code should be like
document.body.addEventListener("ajax:success", (event) => {
const [data, status, xhr] = event.detail;
});