Skip to content
raulriera edited this page May 10, 2011 · 1 revision

Now that you are already familiarized with how to work with basic "Remote Forms" functionality, it is time for some advanced features like "callbacks"

Type of callbacks

Each AJAX submission consist of these callbacks:

  • ajax:beforeSend: fired before the request is dispatched.
  • ajax:success: fired when a positive response is received (this doesn't mean a positive response from your application, but from the actual request of the browser)
  • ajax:complete: fired when the request is completed.
  • ajax:error: fired when there was an error with the request (see ajax:success for more info)

Example

The callbacks explained before are hooked into jQuery as events, so in order to use them all you need to do is "bind" for these events using some JavaScript code:

$(function() {
  $("#yourDOM") 
    .bind("ajax:success", function(event, data, status, xhr) { 
      alert("hi from this event");
    }); 
});

The previous code will listen for the "ajax:success" event and display and alert message back to the user.

Clone this wiki locally