Hello fellow Rails programmers,
I really love the new way of AJAX requests in Rails3. It really cleans
up my HTML code and it makes using AJAX in your application a lot
easier. I only have one - kinda big - problem with it. When the page
is still loading and the user clicks an AJAX link, the AJAX call will
not be executed and he/she will be redirected to another page. That's
because the DOM needs to be loaded before all the links get the AJAX
functions attached to them. I know I should also add HTML callbacks
for these links, but for some AJAX links I don't want the user to see
another page: I want them to see my fancy AJAX and nothing else. I
didn't have this problem when using link_to_remote and wonder if
somebody here knows a solution when using UJS.
I tried adding onclick="return false;" to the links, but the normal
page was still loaded. I asked around for some solutions, but the best
one I got was adding some <div> over the whole page so all links can't
be clicked. Then after the DOM is loaded the <div> can be removed. IMO
that's even worse when it comes to usability, so I wondered if you
people know a fancy solution for my problem.
To sum up my question: I want my AJAX links not clickable until the
DOM is loaded. When the DOM is loaded I want them to have the standard
AJAX functionality they already have. Any suggestions?