I am currently working on a program that involves calling a JavaScript function with multiple requests to a servlet. My goal is to execute these requests one by one and receive a response after each execution. However, the function I have only displays the result after all requests have been completed.
function cmd(args) {
width = 0;
var res = args.split('\n');
var largo = res.length;
var progressLength = 100 / largo;
for (var i = 0; i < largo; i++)
{
if (res[i] == 'desconectar')
{
desconectar();
break;
}
else
{
executeCMD(res[i]);
}
}
}
function executeCMD(args)
{
$.ajax({
type: "POST",
url: 'Controlador',
data: {cmd: args, operacion: 1},
success: function (response) {
document.getElementById('respuesta').value = document.getElementById('respuesta').value + response;
},
dataType: 'text',
async: false
});
}
If I include window.alert(response); within the success function, I am able to see the progress step by step and everything works smoothly. However, this triggers alerts that I would prefer not to have.
My end goal is to achieve something similar to what is shown in this image https://i.sstatic.net/MtaMI.jpg, but currently I am only able to display the last image.