Can I get the requested URL from ajaxStart
? I want to execute a common action for all ajax request accept some few requests.
No, within ajaxStart
you do not have access to the jqXHR
object nor the ajaxOptions
:
// Watch for a new set of requests
if ( s.global && jQuery.active++ === 0 ) {
jQuery.event.trigger( "ajaxStart" );
}
As you can see, there are no arguments being passed to ajaxStart
. Contrast this with ajaxSend
:
// Send global event
if ( fireGlobals ) {
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
}
Where the jqXHR
object is being passed as an argument along with the settings:
$(document).ajaxSend(function(evt, request, settings) {
alert("Starting request at " + settings.url + ".");
});
Also see this answer for a better understanding of this design.
You cant get requested url from ajaxstart function,you can get only using ajaxsend function,because ajaxsend function regarding to the particular request but ajaxstart is not
$( document ).ajaxSend(function( event, jqxhr, settings ) {
if ( settings.url == "ajax/test.html" ) {
$( ".log" ).text( "Triggered ajaxSend handler." );
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With