Very simple: I am using a prepared statement to select data and return it in a json_encode form.
The problem: Instead of receiving a JSON string full of the returned data, I am getting something like this:
[true, true, true, true]
My guess is that it is checking whether every value is set and then it is just returning whether the value is set or not, in a boolean form.
$stmt = $connection->prepare("SELECT * FROM details WHERE age = ?");
$stmt->bind_param('i', $age);
$stmt->execute();
$json = array();
while($row = $stmt->fetch()){
$json[] = $row;
}
echo json_encode($json);
This is the AJAX that I am using.
$(document).ready(
function () {
$('#call_back_btn').click(function() {
$.post("process.php", {
name: $('#name').val(),
age: $('#age').val(),
value: $('#value').val(),
task: "submit_prepared"
},
function(data) {
alert(data);
})
})
});
What should I do so that my data is returned into a JSON string? Thank you.
data=JSON.parse(data);before alerting it.