javascript - 我的 json 请求不会触发 beforeSend 请求。似乎无法弄清楚为什么

标签 javascript jquery

注意事项

  1. 这是 jQuery 1.4.4
  2. 不是 jsonp 请求。只是我域中的普通 json。

我的请求

$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);
  },

当我发送 AJAX 请求时,console.log 不会触发。

您认为问题出在哪里?

最佳答案

docs中说的很清楚

beforeSend(jqXHR, 设置)

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.

关于javascript - 我的 json 请求不会触发 beforeSend 请求。似乎无法弄清楚为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10137667/

相关文章:

javascript - 如何使用 AngularJS 使输出数据动态结构化?

javascript - 如何使用 Javascript 向用户询问随机数学问题?

javascript - CSS - 使用 :nth-child to select an element

javascript - 尝试将字母附加到输入中的文本

php - 图片上传到客户表格作为背景

javascript - 如何在 MongoDB findOne 上返回条件响应?

javascript - 如何处理对google API google.maps.DistanceMatrixService.getDistanceMatrix()的多个请求?

javascript - 根据特定div的属性更改正文背景

jquery - OnActionExecuting 事件未返回 jsonResult

javascript - 用reduce() 计数——值从哪里来?