I have a link in my rails app setup to make an ajax request
= link_to "link text", some_url, :remote => true
I also have a jquery click handler that will change the url when it is clicked
$('a').click(function() {
// change url to "other_url"
});
The problem is that the link changes BEFORE my ajax request is sent. So the first time it’s clicked, instead of going to “some_url” like it should, it ends up going to “other_url” instead.
Is there a simple/easy way to fix this? Currently I have an ajax:complete bound to the link so once the ajax response returns it will update the link. But this doesn’t work for example if the user clicks on the link quickly a few times since the request isn’t returned yet (thus link isn’t updated yet).
I would use the
ajax:beforeSendcallback to disable clicking while the AJAX request is completing. Then, change the URL to the new value in theajax:completecallback.In a click handler
In the
ajax:beforeSendcallback something like….And then in the
ajax:completecallback something like