Undefined Index: Error In Ajax Post And/or Php Script?
I'm trying to send an ajax POST to a php file, however the php file sends a notice of 'undefined index', and the php file never seems to receive the value i'm trying to send it. I'
Solution 1:
There is error in syntax of jquery.. You missed out syntax of data. This should be like this-
functiondeleteMediaFromDatabase(val)
{
$.ajax({ url: 'deleteMediaFromDatabase.php',
data: {'vals' : val},
type: 'post',
dataType:'json',
success: function(output) {
alert(output);
},
error: function(request, status, error){
alert("Error: Could not delete");
}
});
}
Solution 2:
The problem can come from the dataType not being specified or that the dataType specified does not match thus returned by the server.
Explicitely set the dataType, e.g.
dataType:'json'
and make sure that your script returns data that is "encoded" in the data type that you chose, e.g. in PHP:
echo json_encode($something);
Solution 3:
Instead of:
$val = $_POST["vals"];
use this:
if (isset($_POST['vals']) {
$val = $_POST['vals'];
}
Solution 4:
Change Ajax syntax...
$.ajax({
type: "POST",
url: 'deleteMediaFromDatabase.php',
data: {'vals' : val},//Have u tried this
success: function(output) {
alert(output);
}
error: function(request, status, error){
alert("Error: Could not delete");
}
);
Post a Comment for "Undefined Index: Error In Ajax Post And/or Php Script?"