ajax:成功xhr是空的

时间:2018-01-25 15:51:45

标签: javascript jquery ruby-on-rails ajax

我有一个在模态上打开的表单,当它被提交时,响应会显示在同一模态上,遵循这篇文章:https://jtway.co/5-steps-to-add-remote-modals-to-your-rails-app-8c21213b4d0c

但是当我发送表单和ajax:调用成功回调时,xhr,data和status参数始终为null。我检查了event.originalEvent.detail[2].response,它的值只是我预期的响应"数据"。为什么xhr,数据和状态未定义?

(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 个答案:

没有答案