Registering Callbacks with then

$.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).

Figure 14.3  Deferred object invokes callbacks registered with then

Deferred object invokes callbacks registered with then

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 ...

Get Front-End Web Development: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.