$(document).ajaxSend(function(event, request, settings) {
  // IE triggers this event on AJAX GET, which then converts to a POST due to the additional parameter
  if (settings.type == 'GET') return;
  // Add authenticity token to all AJAX requests.  Rails 2.x will reject them otherwise.
  // http://henrik.nyh.se/2008/05/rails-authenticity-token-with-jquery
  if (typeof(AUTH_TOKEN) == "undefined") return;
  // settings.data is a serialized string like "foo=bar&baz=boink" (or null)
  settings.data = settings.data || "";
  settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});
