I have two function which should each send either 0 or 1 on a php page with ajax. when pressing a key on the keyboard, the function that sends 1 starts and the one that sends 0 must start three seconds later with a setTimeout (). The problem is that the second function doesn't send. I send you the party of the corresponding code. Thanking you in advance for your help, and please forgive my not very nice English to read ^^'
My code :
function typing() {
var typingBool = 1
if (typingBool != "") {
let donneee = {}
donneee["typingBool"] = typingBool
let donneeeJson = JSON.stringify(donneee)
let xmlhttp = new XMLHttpRequest()
xmlhttp.open("POST", "ajax/typing.php")
xmlhttp.send(donneeeJson)
}
}
function typing2() {
var typingBool = 0
if (typingBool != "") {
let donneee = {}
donneee["typingBool"] = typingBool
let donneeeJson = JSON.stringify(donneee)
let xmlhttp = new XMLHttpRequest()
xmlhttp.open("POST", "ajax/typing.php")
xmlhttp.send(donneeeJson)
}
}
var typingText = document.getElementById('texte');
typingText.addEventListener('keypress', function() {
typing();
setTimeout(function() {
typing2()
}, 3000);
})