I wan to submit the page data on the same page it self using. I went through several questions and answers but found most of them use Jquery. I don't want to use Jquery. Here's a snippet of code I tried so far..
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("messageID").innerHTML=xmlhttp.responseText;
}
}
let id = "message_id=" + message_id;
xmlhttp.open("POST" , "" , true);
xmlhttp.send(id);
message_id is the value of hidden input type. Now when I run this code. I get the whole page inside my response area. I am using PHP for backend. I have a PHP file included in this page and its a bootstrap modal. In the modal-content part, I have added the code,
if(isset($_POST['message_id'])){
echo $_POST['message_id'];
else{
echo "Not receievd";
}
How to submit ajax data on the same page with vanilla javascript?