通过以下内容,我得到了" undefined"在我的警报中返回()
我有以下AJAX:
$.ajax({
type: "GET",
url: "connect/database.php",
dataType: "json",
success: function(response){
alert(response);
}
});
以下PHP:
$servername = "localhost";
$username = "the_username";
$password = "the_password";
$dbname = "the_db";
// create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$array_result = array();
$sql = mysqli_query("select * from table where user = 'bobo'");
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$array_result[] = $row;
}
} else {
echo "0 results";
}
$conn->close();
print json_encode($array_result)
?>