For what you want the ideal will be to create an array of names and as you go through it makes ajax requests creating and configuring the objects XMLHttpRequest
:
const url = "http://www.a_sua_pagina_aqui.php";
const nomes = ["Fernando","Lucas"];
nomes.forEach((nome) => { //percorrer todos os nomes
const xhttp = new XMLHttpRequest(); //criar o objeto para o pedido
xhttp.onreadystatechange = function() {
//apenas dentro do if tem a resposta à requisição
if (this.readyState == 4 && this.status == 200) {
console.log(xhttp.responseText); //resposta vem no responseText
}
};
xhttp.open("POST", url , true); //requisição do tipo POST com true para ser assíncrono
xhttp.send("nome=" + nome); //parâmetros enviados aqui, neste caso apenas o nome
});
It is important to remember that the order in which you receive the answers will not necessarily be the order in which you sent them!
And each name should be a separate ajax right? Where do you want to show these results? do you want to show as they come or all together.
– Sergio
Each name will be a separate request, I want to show in a simple Alert for now and go showing as they come, thanks so much for the help ;)
– Stan
But requests
get
orpost
? In the title is one thing but then in the middle of the question is another– Isac