Sending the order to the server
Once you can communicate with the server to manage our products, it's time to send the order. For this purpose, follow these instructions:
- Create a file named
resources/OrderResource.js
with this content:'use strict'; var OrderResource = (function () { function create(order) { return $.ajax({ type: 'PUT', url: '/order', data: order }); } return { create: create }; })();
- Mock the call by creating a file called
mocks/order.js
and adding this code:$.mockjax({ type: 'POST', url: '/order', status: 200, responseTime: 750, responseText: { 'data': { text: 'Order created' } } });
- Update the
finishOrder
method in theviewmodel.js
file:var finishOrder = function() { OrderResource.create().done(function(response){ cart([]); visibleCart(false); ...
Get KnockoutJS Essentials 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.