I want to send multiple variables to a php file within one XMLHttpReqyest , I can send 1 but I can't figure how to send more than 1.
for example if I have:
The HTML:
<form method="POST">
<input type="text" id="firstVal"/>
<input type="text" id="secondVal"/>
<input type="submit" id='send'/>
</form>
The JS:
var val1 = documennt.getElementById('firstVal');
var val2 = documennt.getElementById('secondVal');
var sendData = documennt.getElementById('send');
function checkData(){
var xhr = new XMLHttpRequest();
xhr.open("POST" , 'file.php' , true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
console.log(xhr.responseText);
}
}
xhr.send();
}
sendData.addEventListener('click' , checkData);
How to send these variables to the file.php ?