Philip Kirkbride Philip Kirkbride - 1 month ago 5
Javascript Question

How to use jQuery .When .done

I'm trying to run one function after another function completes.

$.when(saveCanvas(canvas)).done(setWallPaper());


Each function works fine on it's own but when I run the code above it only runs the first function.

What do I need to change?

Answer

Looking back at this now, this seems to be how it works with jQuery:

function f1() {
	alert("function one");
}

$.when( f1() ).done(function() {
  alert("function 1 is done running function two");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Note: This is identical to my method I posted in the question so essentially it should have worked. Though jQuery may have changed over the last 3 years.

Comments