<a class="option option-equal" href="/articles/22/action" data-remote="true" data-method="post" id="article_top"></a>
<script type="text/javascript" charset="utf-8">
  $(function () {
      $("#article_top").on("ajax:before", function (e) {
         if (PageValue.user_id == ""){
             return false;
         }
      }).on("ajax:beforeSend", function (e, xhr, options) {
          alert("beforeSend")
          alert("xhr " + xhr)
          alert("options " + options)
      }).on("ajax:success", function (e, xhr, status, err) {
          alert("success");
          alert("event: " + e)
          alert("xhr : " + xhr)
          alert("status : " + status)
          alert("data : " + err)
      })
  })
</script>
我 debug,看了 ujs 的源代码
beforeSend: function(xhr, options) {
            if (fire(element, 'ajax:beforeSend', [xhr, options])) {
              return fire(element, 'ajax:send', [xhr]);
            } else {
              fire(element, 'ajax:stopped');
              return xhr.abort();
            }
          }
fire = Rails.fire = function(obj, name, data) {
        var event;
        event = new CustomEvent(name, {
          bubbles: true,
          cancelable: true,
          detail: data
        });
        obj.dispatchEvent(event);
        return !event.defaultPrevented;
      };
| 事件名 | 额外参数 | 触发时机 | 
|---|---|---|
| ajax:before | 在整个 Ajax 调用开始之前,如果被停止了,就不再调用。 | |
| ajax:beforeSend | xhr, options | 在发送请求之前,如果被停止了,就不再发送。 | 
| ajax:success | xhr, status, err | Ajax 调用结束,返回表示成功的响应时。 |