MarkUs Blog

MarkUs Developers Blog About Their Project

Absence of an AJAX “before” Event Handler

with 2 comments

With the advent of Rails 3 and Unobtrusive Javascript, we have had to replace a lot of the inline Prototype Javascript code with calls to functions within the rails.js file which contains many Prototype Javascript functions and AJAX event handlers. However, I have come to realize that the AJAX “before” handler is missing. After looking around and debubbing, I have still not come across some AJAX before handler. As a result, Javascript code that we run before an AJAX request is not executed. This im my opinion is what has led to the log in button from the log in screen and the role switching dialog not being disabled on logging in. I realized that the initial fix I put up for review of issue 641 was wrong as I modified the after event. Instead I should be adding an AJAX “before” handler. I need input on whether the idea is senseless or not.

[EDIT] I created a ticket in Prototype Project. Here is the link

Here are some of the references I used:


Written by Tobi

February 19th, 2012 at 12:16 pm

Posted in Uncategorized

2 Responses to 'Absence of an AJAX “before” Event Handler'

Subscribe to comments with RSS or TrackBack to 'Absence of an AJAX “before” Event Handler'.

  1. Implementing an ajax:before sounds good to me. We do something similar somewhere else as well. Perhaps it’s a good idea to not do it in rails.js, but in one of our JS files.

    Better yet, don’t use :disable_with at all and bind to ajax:before and ajax:complete directly and do your thing. Up to you really 🙂

    As far as I understand, all :disable_with is doing is setting the data-disable-with attribute of the input HTML element. I.e. it could be useful to use and just retrieve the value from your ajax:before handler. Thoughts?


    19 Feb 12 at 6:38 pm

  2. Yes :disable_with just disables the button and sets the data-disable-with attribute of the input HTML element. I could do it in one of our JS files. For now I have filed a bug on the Prototype project because it seems like something that should be supported off the bat. I attached a diff to the bug I filed. I will wait to hear a response from them and then take next steps. For now, I will work on something else.


    19 Feb 12 at 7:43 pm

Leave a Reply