jquery-ujs
jquery-ujs copied to clipboard
Doubt in community regarding proper order of parameters for ajax: callbacks
If you look at the page history for Custom events fired during "data-remote" requests, you can tell that there is significant confusion regarding what is the proper order of the parameters passed to custom event callbacks. In the last year there have been 6 or 7 different people with good intentions trying to get this cleared up.
The source code suggests the following:
- ajax:beforeSend: [xhr, settings]
- ajax:success: [data, status, xhr]
- ajax:complete:[xhr, status]
- ajax:error: [xhr, status, error]
I have modified the wiki page today to reflect this, but perhaps someone with authoritative knowledge can go in and add a definitive clarification so that it doesn't keep getting switched back and forth?
I was confused by this until I looked http://api.jquery.com/jQuery.ajax/ and it looks like jQuery has the same issue with parameters being out of order as well.
jQuery is moving away from success, complete, error to done, fail, always.
Maybe this library should as well and call something like ajax:done with them in the now correct jQuery order.
someone edited the wiki again few hours ago to the order which doesn't reflect actual order... (and confused me why xhr
returning html since I haven't used this for a long while)