How can I get the requested url from ajaxStart function?
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." );
}
});
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.