How can I get I return the response in ajax call,
I have tried with below code
function getDiscountAmount()
{
for (var i = 0; i < invoice_ids.length; i++) {
promises.push(getInvoiceAmountData(amount_tds, invoice_ids[i]));
}
Promise.all(promises).then((responses) => {
var data= responses // need to return the response here
})
return data;
function getInvoiceAmountData(amount_tds, invoice_id) {
return $.ajax({
url: "payments/getInvoiceAmount",
method: "post",
dataType: 'json',
data: {"amount_tds": amount_tds, "invoice_id":invoice_id}
});
}
}
And now get that response in different function
function getResponse()
{
console.log(getDiscountAmount()) //it gives undefined
}