The beforeSend
callback takes two arguments: the XMLHTTPRequest
instance and the settings used by the current AJAX call.
Therefore, if you pass the triggering element and event in the context
option, they will be available to beforeSend
even if you define it in the global setup:
$.ajaxSetup({
beforeSend: function(xhr, settings) {
var element = settings.context.element;
var event = settings.context.event;
// Do something with 'element' and 'event'...
}
});
$("selector").click(function(e) {
$.ajax("url", {
// your settings,
context: {
element: this,
event: e
}
});
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…