I have the following set up where my main()
function makes an AJAX call and calls getValue1()
and getValue2()
inside SUCCESS. I am learning how to use the keywords async and await
According to this SO post and this developer manual, the following code should work. However, it doesn't. Can someone tell me why?
async function main() {
$.ajax({
url: "...",
success: function (object) {
var html = '';
for (var i = 0; i < object.length; i++) {
var value1 = await getValue1(object[i].value1);
html += '<p>' + value1 + '</p>';
var value2 = await getValue2(object[i].value2);
html += '<p>' + value2 + '</p>';
console.log(html);
}
}
});
}
function getValue1(value1) {
$.ajax({
url: "...",
success: function (value1) {
return value1;
}
});
}
function getValue2(value2) {
$.ajax({
url: "...",
success: function (value2) {
return value2;
}
});
}