I need to do some (potentially asynchronous) stuff before sending an AJAX-request via jQuery. Is there any way to evoke the sending of the request on a jqXHR object manually? The problem is that I need to immediately return the jqXHR object (e.g. to use the $.Deferred() interface)
Asked
Active
Viewed 395 times
0
-
1Don't call `$.ajax` until you want to send the request? – jbabey Mar 18 '13 at 13:15
-
The `jQuery.ajax()` function already immediately returns the `jqXhr` object. Could you provide more details - and some code - showing what exactly you want to achieve? – Anthony Grist Mar 18 '13 at 13:16
-
1Not that I know of... if you provide more information about your problem, we might be able to come up with an alternative solution. You know that you can always create your own promise objects? – Felix Kling Mar 18 '13 at 13:16
-
Under a certain condition I want to perform another request before I perform the current one. COnsequently, I cannot use beforeSend since it is not asynchron. – Leo Selig Mar 18 '13 at 14:29
-
But I also have to return the jqXHR of the future request immediately – Leo Selig Mar 18 '13 at 14:30
1 Answers
1
you can use beforeSend
event in jQuery
$.ajax({
url: "url",
beforeSend: function ( xhr ) {
// you can do here
}
}).done(function ( data ) {
.............
});

PSR
- 39,804
- 41
- 111
- 151