I have a turbo:submit-end event. I want to get the response body when the event fires. Assuming it's possible, how can I do this?
You can do this to get the response in the js.
lets say you have this form which triggers the turbo:submit-end
<%= form_with(url: some_path, data: {  action: 'turbo:submit-end->some-js-controller#someActionMethod' }) do |f| %>
now to get the response, you have to do something like this:
someActionMethod(event) {
    event.detail.fetchResponse.response.text().then(value => {
      //value contains the response, if response is html, if response is 
      //json, event.detail.fetchResponse.response.json() (did not try, 
      //should work)
    })
  }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With