【发布时间】:2015-02-13 20:48:51
【问题描述】:
我无法弄清楚我的 ajax 调用出了什么问题,我只是想从我的 php 文件中显示 json。非常感谢任何帮助。
PHP (phonecall.php):
<?php
$con = mysqli_connect('localhost','root','root','mydb');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"mydb");
$sql="SELECT * FROM incoming_calls";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$callArray[] = array('phonenumber' => $row['phone_number'], 'id' => $row['phone_login_id']);
echo json_encode($callArray);
}
mysqli_close($con);
?>
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Phone calls</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<script language="javascript" type="text/javascript">
$.ajax({
type: "GET",
url: "phonecall.php",
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response){
$("#call").html(response);
}
});
</script>
<div id="call"></div>
</body>
</html>
我的 div 标签中没有显示任何内容。有什么想法吗?
【问题讨论】:
-
你看过浏览器控制台中的请求/响应吗?
标签: javascript php jquery ajax mysqli