I would like to send POST parameters to a controller through AJAX but without jQuery. How should I do?
function myFunction() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("myDiv").innerHTML = this.responseText;
}
};
//Add the POST parameters
xhr.open("POST", "my_controller.php", true);
xhr.send();
}
<button type="button" onclick="myFunction">Send POST parameters</button>
<div id="myDiv"></div>
Thank you for your help.