I have a form which is open on a modal and when it is submitted the response is displayed on the same modal, following this article: https://jtway.co/5-steps-to-add-remote-modals-to-your-rails-app-8c21213b4d0c
But when I send the form and the ajax:success callback is invoked, xhr, data and status parameters are always null. I checked on event.originalEvent.detail[2].response and its value is just the response I was expected on "data". Why are xhr, data and status undefined?
(function() {
$(function() {
var modal_holder_selector, modal_selector;
modal_holder_selector = '#modal-holder';
modal_selector = '.modal';
$(document).on('click', 'a[data-modal]', function(event) {
var location;
event.preventDefault();
location = $(this).attr('href');
$.get(location, function(data) {
return $(modal_holder_selector).html(data).find(modal_selector).modal();
});
return false;
});
return $(document).on('ajax:success', 'form[data-modal]', function(event, data, status, xhr) {
var url;
event.preventDefault();
// XHR, STATUS and DATA are always undefined!! ¿?
url = xhr.getResponseHeader('Location');
if (url) {
window.location = url;
} else {
$('.modal-backdrop').remove();
$(modal_holder_selector).html(data).find(modal_selector).modal();
}
return false;
});
});
}).call(this);