I have a function that sends a post request to a php website. I get 2 different behaviors by simply changing the capitalization of a variable. The variable in question is the 'action' variable and either being set to "deleteIndexMain" or "deleteIndexmain" If the action variable is set to "deleteIndexmain" I get the popup displaying the html that the php returns. If I set the variable to "deleteIndexMain" I get no popup. (meaning it appears to be a javascript issue?
Here is the java script code:
function deleteMe(v,r)
{
if(confirm("Are you sure"))
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if(xhttp.readyState == 4 && xhttp.status == 200)
{
alert(xhttp.responseText);
document.getElementById("indexmaintable").deleteRow(r);
}
};
xhttp.open("POST", "includes/control.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("action=deleteIndexMain&file="+v);
}
}
and here is the php code:
<?php
//Todo make sure to authenticate!
session_start();
require_once("config.php");
function deleteIndexMain($file)
{
unlink($file);
$query = 'DELETE FROM indexmain WHERE linklocation="'.$file.'"';
$db->query($query);
}
print_r($_POST);
if(isset($_POST) && $_POST['action'] == "deleteIndexMain")
{
echo 'Deleting '.$_POST['file'];
deleteIndexMain($_POST['file']);
}
?>