Posts [ 3 ]

Topic: ajax before:send, success, complete requests not working

I am new to using Jquery in Rails. Could anyone provide a working example of a message that content is loading. I do not want to use the global ajaxStart because I don't want it called everytime. I have partials that are pretty content heavy and would like to have a message just pop up telling people it is loading. I have looked around and see bits and pieces of code to accomplish this, but I don't seem to grasp where all this goes. Anything to point me in the right direction would be great.

Re: ajax before:send, success, complete requests not working

Are these partials loading on the page load? So when you come to the page, there are several different sections that are loading content and you want to give a spinner (similar to something like an iGoogle homepage)?

From your code it looks like you want to load the partials when you click the "Health & Beauty" link. If so, this would work. In concept, you're giving the remote link a CSS class to grab a hold of. The jquery rails plugin does this differently; I think it has a data-remote attribute? Can't remember...but you could grab that element instead of the class if you wanted.

What this code does is when you click the link it shows the spinner. Your AJAX request then hits the server, which does some processing, and then the server returns javascript code to be executed by the browser which hides the spinner.

Re: ajax before:send, success, complete requests not working

looloobs: I think you want to remove the semicolons at the end of the beforeSend and success bind calls. They break the chaining of the calls.

You can think of it as writing thing.set_firstname('a');.set_lastname('b'); instead of thing.set_firstname('a').set_lastname('b'). See how the extra semicolon in the middle of the first version orphans the call to set_lastname so that it no longer refers to thing?