LoginSignup
0
1

More than 5 years have passed since last update.

rails-ujs + jquery での 罠

Posted at

rails-ujs を使い、jquery の onメソッドで form の ajax イベントをつかむときにはまったので備忘録

フォームやリンクで data-remote="true" したときなど、ajax:successのイベントを拾うとき以前の追加パラメータ(xhr, status, errなど)は、event.detailの配列として入るようにかわった。

$("form").on "ajax:success", (event) ->
  console.log(event.detail[0])

こんな感じでとるとエラー

e.png

jQuery のリファレンス読むと

Other Properties
To access event properties not listed above, use the event.originalEvent object:

(和訳)

APIリストにないイベントプロパティは event.originalEvent 使えや

というわけで、

$("form").on "ajax:success", (event) ->
  console.log(event.originalEvent.detail[0])

で、無事とれました。

jQuery 1.11.2

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1