简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM