I would like to bind .on()
to an ajax "event", meaning that I'd like it to be triggered whenever an ajax response is successfully retrieved.
I don't get how I could bind .on()
to such an event. Do I need to use load
like so?
$(document).on('load','#elementInsertedByAjax',function(){
// will do something
});
PS I do need to use .on()
since the whole page is inserted by an ajax call.
What is AJAX success? AJAX success is a global event. Global events are triggered on the document to call any handlers who may be listening. The ajaxSuccess event is only called if the request is successful. It is essentially a type function that's called when a request proceeds.
Call function after ajax complete You can simply copy/paste code in the body tag of the html page and reload page to get the content form https://api.joind.in/v2.1/talks/10889 URL after success and call callFunctionAfterAjaxCallComplete() function after ajax request is completed.
You can store your promise, you can pass it around, you can use it as an argument in function calls and you can return it from functions, but when you finally want to use your data that is returned by the AJAX call, you have to do it like this: promise. success(function (data) { alert(data); });
What triggers Ajax success? Whenever an Ajax request completes successfully, jQuery triggers the ajaxSuccess event. Any and all handlers that have been registered with the . ajaxSuccess() method are executed at this time.
You can use .ajaxSuccess()
$(document).ajaxSuccess(function() {
// will do something
});
or bind to
$(document).on('ajaxSuccess','#elementInsertedByAjax',function(){
// will do something
});
You can use the ajax global event jQuery.ajaxSuccess
$(document).ajaxSuccess(function() {
$( ".log" ).text( "Triggered ajaxSuccess 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