weixin_33705053 2018-01-25 15:51 采纳率: 0%
浏览 184

ajax:成功xhr为空

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);
  • 写回答

0条回答 默认 最新

    报告相同问题?