Table: RailsNotes
User: dreamable
Created at: 2021-02-04 01:59:51 UTC
Updated at: 2021-02-04 01:59:51 UTC
Reference:(Table ID 3, Record ID 18)

标题 :
AJAX events
笔记 :

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;
});
Tag: