JQuery.on () on ajax success

I would like to bind .on() to the ajax event, which means I would like it to fire whenever the ajax response was successfully received. I do not understand how I could bind .on() to such an event. Do I need to use load like this?

 $(document).on('load','#elementInsertedByAjax',function(){ // will do something }); 

PS I need to use .on() as the whole page is inserted by ajax call.

+5
jquery ajax events
source share
3 answers

You can use .ajaxSuccess()

 $(document).ajaxSuccess(function() { // will do something }); 

or bind to

 $(document).on('ajaxSuccess','#elementInsertedByAjax',function(){ // will do something }); 
+8
source share

You can use the ajax jQuery.ajaxSuccess global event

 $(document).ajaxSuccess(function() { $( ".log" ).text( "Triggered ajaxSuccess handler." ); }); 
+1
source share
 $,ajax({ url:'yoururl', type : 'GET', /*or POST*/ data: {'d1',data1}, /*if any*/ success:function(returndatafromserver){ //here you can check the success of ajax },error:function(errormsg){ //error if any } }); 
0
source share

All Articles