简体   繁体   中英

JQuery AjaxSetup BeforeSend Promise

I want to return a Promise from a beforeSend interceptor for jQuery. Basically I have a function registered as beforeSend which performs some asynchronous work. I want to defer the AJAX request from executing until my asynchronous work has completed. I know I can return false to cancel the AJAX request from beforeSend , but what about deferring it?

Seems that you are in trouble. BeforeSend for instance can return a boolean value so it loses the promisses benefits. One workaround is create an ajax request and create a new ajax request as a callback in done function. A cascade ajax request should solve your problem.

$.ajax({}).done(function() { $.ajax({}).done(function() {})})

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