Hello, I am trying to send a variable from an AJAX JavaScript file to a PHP file. Here is what I have done so far:
var request = createRequest();
var deletenode = node.id;
window.alert("nodeid=" + deletenode);
var vars = "deletenode="+deletenode;
request.open("POST", "deletenode.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
handleRequest(request);
};
request.send("deletenode=" + encodeURIComponent(deletenode));
This is my PHP file:
<?php
print_r($_POST);
$node = $_POST['deletenode'];
print "Node to be deleted: $node";
?>
I am not seeing anything in my PHP file. What could the issue be? My AJAX request seems to be working correctly. Thank you, and here is my handle request function:
function handleRequest(request) {
if(request.readyState == 4){
json= eval ("(" + request.responseText + ")");;
closeButton.onclick = function() {
node.setData('alpha', 0, 'end');
node.eachAdjacency(function(adj) {
adj.setData('alpha', 0, 'end');
var request = createRequest();
var deletenode = node.id;
window.alert("nodeid=" + deletenode);
var vars = "deletenode="+deletenode;
request.open("POST", "deletenode.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
handleRequest(request);
};
request.send("deletenode=" + encodeURIComponent(deletenode));
});
}
}
}