ajax using jquery
jQuery’s ajax method’s
success callback function takes three
parameters. Here is the api .
So if you are making ajax call using jQuery the code might look like
1 2 3 4 5 6
ajax using jquery-ujs
If you are using Rails and jquery-ujs then you might have code like this
1 2 3 4 5
Above code will not work. In order to make it work the very first element passed to the callback must be an event object. Here is the code that will work.
1 2 3
Remember that jQuery api says that the first parameter should be “data” then why we need to pass event object to make it work.
Why event object is needed
Here is snippet from jquery-ujs code
1 2 3
The thing about trigger method is that the event object is always passed as the first parameter to the event handler. This is why when you are using jquery-ujs you have to have the first parameter in the callback function an event object.