I'm doing a little program which when the user clicks, it invokes 2 functions that do different things.
When I click they send both (I checked it in the Chrome developer tools) and in fact they respond correctly to both PHP, however when they return, only the second div appears full, the first one is not filled.
I tried to invoke function 2 on the 1, but now the first one is executed and not the second one.
I sent it to call just below this line:
document.getElementById("employee").innerHTML = xmlhttp.responseText;
}function getInteractions(str);
};
but it did not work: '(
Could you recommend me what I can do? Here is part of my code
JAVASCRIPT + AJAX
function getEmployees(str) {
if (str == "") {
document.getElementById("employee").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("employee").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "getEmployees.php?q=" + str, true);
xmlhttp.send();
}
}
function getInteractions(strg) {
if (strg == "") {
document.getElementById("interaction").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("interaction").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "getInteractions.php?a=" + strg, true);
xmlhttp.send();
}
}
HTML
<input type="text" id="theid" name="theid" placeholder="Escribe tu número de empleado" />
<button onclick="getEmployees($(#theid).val());getInteractions($(#theid).val());">Enviar</button>
<div id="employee"></div>
<div id="interaction"></div>