Trip
Trip

Reputation: 27114

My json request will not fire a beforeSend request.. Can't seem to figure out why

Notes

  1. This is jQuery 1.4.4
  2. This is not a jsonp request. Just vanilla json within my domain.

My Request

$autocomplete_xhr = $.ajax({
  url: '/customers/filter.json',
  contentType: "application/json",
  data: { name: request.term },
  dataType: 'json',
  beforeSend: function(xhr) {
   console.log('Inside beforeSend');
   console.log(xhr);
  },

When I send the AJAX request out, console.log will not fire off.

What do you think the problem is?

Upvotes: 1

Views: 400

Answers (1)

xkeshav
xkeshav

Reputation: 54050

clearly said in docs

beforeSend(jqXHR, settings)

A pre-request callback function that can be used to modify the jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object before it is sent. Use this to set custom headers, etc. The jqXHR and settings maps are passed as arguments. This is an Ajax Event. Returning false in the beforeSend function will cancel the request. As of jQuery 1.5, the beforeSend option will be called regardless of the type of request.

Upvotes: 3

Related Questions