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"} %> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 23 Feb 2009, at 10:46, David wrote:> > 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"} %>You could use :before / :onComplete callbacks to disable stuff (either by setting some js variable or just disabling the link) Fred> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 false;}, } ); } 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 Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 23 Feb 2009, at 10:46, David wrote: > > > > > 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"} %> > > You could use :before / :onComplete callbacks to disable stuff (either > by setting some js variable or just disabling the link) > > Fred > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I had a similar problem recently, and was able to effectively disable the link (and prevent multiple clicks) by using the :before directive: :before=>"this.style.display=''none''" Note: this was only tested in Safari and Firefox... On Feb 23, 4:46 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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"} %>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---