Hello, I am making a request to searchRand.php, in the php I make a query to obtain data. And I save it in the $ to_return variable. But when returning the value of $ to_return does not return anything. Being in the php command print the variable $ to_return before returning it and if it contains values but the ajax does not receive anything. Please help, I do not know what's happening.
Ajax code:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "access/searchRand.php",
dataType: "json",
success: function (response) {
console.log(response)
}
});
});
PHP code:
<?php
require 'dbconn.php';
if($qry = $conn -> query('SELECT * FROM producto')){
while($row = $qry -> fetch_assoc()){
$to_return[] = $row;
}
echo json_encode($to_return);
$conn->close();
}else{
$conn->close();
return json_encode(array('status' => 'internal error'));
}
?>