Disable double-click with link_to_remote

I’m using link_to_remote to load and show a number of partials and am
looking for a way to prevent multiple clicks on the link. I tried
searching around, but couldn’t really find anything. The way it is
set up now is that if a user double clicks fast enough, two ajax
requests are sent to the server and when both are loaded, things get
messed up. I’m looking for a good way to eliminate the possibility of
that second ajax request. Is that possible using link_to_remote?
This is one of my link_to_remotes:

<%= link_to_remote "Show", :url => {:action => "show"} %>

On 23 Feb 2009, at 10:46, David wrote:

<%= link_to_remote “Show”, :url => {:action => “show”} %>
You could use :before / :onComplete callbacks to disable stuff (either
by setting some js variable or just disabling the link)


Heres what I have and it seems to work:

$('popup_link_<%= @day %>').observe('click', function()

if(!making_ajax_request) {
making_ajax_request = true;
new Ajax.Request( ‘/users/serve_popup’, { parameters: { day: <
%= @day %>},
onComplete: function(){ making_ajax_request =
} );
} else { }


Does anyone have any suggestions or see anything wrong? I am
wondering if it would be better to use onSuccess rather than
onComplete, but maybe not, b/c then if an ajax.request was
unsuccessful the making_ajax_request would be left as true and the
user would be unable to make another ajax request.

On Feb 23, 3:12 am, Frederick C. [email protected]

I had a similar problem recently, and was able to effectively disable
the link (and prevent multiple clicks) by using the :before directive:


Note: this was only tested in Safari and Firefox…