How to properly utilize jQuery Deferred/promise on auto-invoked function such as .ajax()'s beforeSend()?
问题 I'm working on extending jQuery's ajaxPrefilter interface to add additional functionality to AJAX calls; namely tacking header data onto the XHR request using setRequestHeader() within the beforeSend() method. The thing is, both the ajaxPrefilter and ajax call itself could contain beforeSend options, and one or both of them could contain async functionality. Assume my ajaxPrefilter looks as such: (function($) { $.ajaxPrefilter(function(options, originalOptions, jqXHR) { var auth = $.cookie(