$.ajax returns a Deferred
, which has a
then method.
The then method registers a callback that is
run when the Deferred
is resolved. When the callback is invoked,
it is passed the value sent back in the server response (Figure 14.3).
Start with a simple usage of then. In main.js, your submit handler calls createOrder and addRow. Change this so that addRow is registered as a callback of createOrder.
Open main.js and update the call to formHandler.addSubmitHandler. Chain a .then to the invocation of createOrder. Pass it a callback that runs checkList.addRow.
... formHandler.addSubmitHandler(function (data) { myTruck.createOrder.call(myTruck, data);.then(function () { checkList.addRow.call(checkList, data); }); }); ...
Instead of invoking addRow immediately after createOrder, you are making addRow dependent on createOrder completing without errors or exceptions.
3.12.136.186