In the following function, the $.when() never triggers. It goes right to the .then().
None of the console.log statements within that function fire, nor does the ajax query when it meets the criteria that would trigger the ajax
Why?
$(`#btnUpdatePrice`).on(`click`, function() {
console.log(`updating stuff`);
curCell.attr(`spactualprice`, $(`#priceModalNewPrice`).val());// - ($(`#priceModalNewPrice`).val() * discountRate));
curCell.attr(`personalizationQuantity`, $(`#tbPersonalization`).val());
const dfd = $.Deferred();
$.when(function() {
console.log(`starting function: `, $(`#QtyM186610`).length);
if ($(`#QtyM186610`).length) {
const tval = +$(`#QtyM186610`).val() + (+$(`#tbPersonalization`).val());
console.log(`personalization item already exists: `, tval);
$(`#QtyM186610`).val(tval);
return dfd.resolve();
} else {
return $.ajax({
url: `KP_AdminEditOrder_Ajax.asp`,
type: `POST`,
data: {prodList: `186610`, action: `addProducts`, ATBPricing: objCustomer.ATBPricing, custType: objCustomer.customerType, orderId: objOrder.idOrder},
beforeSend: function() {
},
}).done(function(data) {
const results = parseReturn(data);
const tProds = results.ProductInfo;
const firstProd = tProds[0].parentProd;
curParentProduct = -1;
objProducts = objProducts.concat(tProds);
objProducts.forEach((product) => {
if (product.orginalProd === -1) return;
displayProduct(product, true);
});
totalQuant = 0;
totalPrice = 0;
totalRowQuant = 0;
totalRowPrice = 0;
curParentProduct = -1;
$(`html, body`).scrollTop($(`[idparentprd="${firstProd}"]`).offset().top);
$(`#QtyM186610`).val($(`#tbPersonalization`).val());
}).fail(function(xhr, textStatus, errorThrown) {
});
}
}).then(function() {
console.log(`recalc from price update`);
recalcRow(curCell);
});
curCell=``;
});