I am trying to send ajax POST to a php file, however the php file sends a "undefined index" notification, and the php file never gets the value I'm trying to send. I was looking for the answer to why this is not working properly, so hopefully someone can give me some insight.
My javascript function gets the value from html and gets the correct value. (in this case it is "1")
function deleteMediaFromDatabase(val)
{
$.ajax({ url: 'deleteMediaFromDatabase.php',
data: {vals : val},
type: 'post',
success: function(output) {
alert(output);
},
error: function(request, status, error){
alert("Error: Could not delete");
}
});
}
Here is the part of my php file that should receive the message:
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL);
$val = $_POST["vals"];
$con = mysqli_connect(<stuff you don't care about>);
error_log($val . ' is the value', 3, "./error.log");
?>
I, however, get this error message from php:
Note: Undefined index: vals in /xxx/xxx/htdocs/AdminPanel/deleteMediaFromDatabase.php on line 9
And my javascript always displays a warning in the error: "Error: failed to delete"
, , , - , , , . ( )...