注意事项
- 这是 jQuery 1.4.4
- 这不是 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/