I send a value with js/ajax to the same page
the console.log show the correct value but $_POST is empty or not defined after load page
this is my code what did i miss?
<script>
var xmlHttpObject = false;
if (typeof XMLHttpRequest != 'undefined') {
xmlHttpObject = new XMLHttpRequest();
}
if (!xmlHttpObject) {
try { xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e) {
try { xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) { xmlHttpObject = null; }
}
}
function load_data(){
if (xmlHttpObject.readyState == 4){
var GetXON = xmlHttpObject.GetXIN;
document.getElementById(GetXON).innerHTML = xmlHttpObject.responseText;
}
}
function get_data(N){
var N = N;
var DATA ='data='+N;
console.log(DATA);
xmlHttpObject.open('post','',true);
xmlHttpObject.GetXIN = 'book';
xmlHttpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpObject.onreadystatechange = load_data;
}
</script>
<button onclick="get_data('1')">Send Value</button>
<div id="book">
<?php echo $_POST['data']; ?>
</div>