I've been trying to figure out what i'm doing wrong for a day now and tried all kinds of things to make this work.Basically i send a var named id through POST to a php file which then runs a query with it and brings back data. print_r
shows that the correct data has been sent (a single number in this case)but instead of the query returning with the names etc it just doesn't recognise the $_POST['id']
and returns with an error.
$(document).ready(function() {
$(".side-menu_description").click(function() {
var id = $(this).attr("id");
if ($.trim(id) != "") {
/*
$.post("index_loads/series_load.php", { 'id': id }, function(data) {
alert(data);
$("#wrap").fadeOut("slow").load("index_loads/series_load.php").fadeIn("slow");
});
*/
$.ajax({
url: 'index_loads/series_load.php/',
data: { "id": id },
type: 'POST',
success: function(data) {
$("#wrap").fadeOut("slow").load("index_loads/series_load.php").fadeIn("slow");
alert(data);
},
error: function(){
alert("Error: Could not return");
}
});
}
});
});
<?php
print_r($_POST);
//$_POST['id'] = file_get_contents('php://input');
$q = "SELECT * FROM Series WHERE SeriesID = '$_POST[id]'";
$r = mysqli_query($dbc, $q);
$data = mysqli_fetch_assoc($r);
?>
The first few lines of the alert :
Array
(
[id] => 5
)
<h1> </h1>
<!--<h2>
Airs At: <br />
<b>Notice</b>: Undefined offset: 1 in <b>C:\xampp\htdocs\myname\index_loads\series_load.php</b> on line <b>24</b><br />
: </h2>-->
<h3>Rating:<br> Stars + (4.0)</h3>
I've tried all kinds of things from using $.ajax
to changing data to { "id=" + id}
to file_get_contents
but none of them seem to work. I'm probably missing something but after searching i still can't find the answer!
Thanks in advance.