Before we move on any further, we need to show a modal to the user where they can enter their shipping address. The modal will be opened once the Place Order button is clicked, as shown in the following screenshot.
The following code snippet illustrates the click event for Place Order (the modal is opened if cart items are present):
$('#btnPlaceOrder').click(function ()
{
var cartItems = $('#tblCart tbody tr');
// If Cart items present, then show modal to enter Shipping Address.
if (cartItems.length > 0) {
$('#Order').modal('show');
return;
}
alert("Please add items into the cart.");
});
An Ajax call inserts an order's record in the database by clicking Submit using POST. The following code snippet is the click event of Submit:
$('#btnConfirmOrder').click(function () {
PostOrders();
});