Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a js function only after the ajax request fully compleated

I want to execute a js function only after the jquery ajax call fully completed.(After Success and Error Events completed). ie after ajax call puts incoming data to an element.

How to achive this.

like image 637
Shibin V.M Avatar asked Nov 25 '11 16:11

Shibin V.M


People also ask

How do you call a function after a success on AJAX?

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.

How would you fire a callback when any AJAX request on a page has completed?

The ajaxComplete() method specifies a function to be run when an AJAX request completes. Note: As of jQuery version 1.8, this method should only be attached to document. Unlike ajaxSuccess(), functions specified with the ajaxComplete() method will run when the request is completed, even it is not successful.

How do you trigger a change event after AJAX call?

ajax({ url, data: data, type: "POST", dataType: "json", success: function(cbdata) { update_table(cbdata); } }); } $('#selector'). on('click', changeDate); So you can call changeData() when you need it.

How do I know AJAX call is complete?

The ajaxStop() method specifies a function to run when ALL AJAX requests have completed. When an AJAX request completes, jQuery checks if there are any more AJAX requests. The function specified with the ajaxStop() method will run if no other requests are pending.


1 Answers

You should use $.ajaxComplete();

$(document).ajaxComplete(function() {
  alert("compete");
});

this would be triggered after every Ajax call you make on the page

otherwise you use ajax() and set the complete property

$.ajax({
  url: "myurl",
  complete: function(){
              alert("complete");
            }
  //set all the other options as usual
like image 166
Nicola Peluchetti Avatar answered Oct 19 '22 06:10

Nicola Peluchetti