jQuery ajax get call
jQuery ajax get call
我无法弄清楚我的ajax调用出了什么问题,我只是试图显示我的php文件中的json。任何帮助将不胜感激。
PHP(电话.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 标签中没有显示任何内容。有什么想法吗?
您正在多次写入数组,只需执行一次,请检查控制台以检查响应是否正确。
$callArray = array();
while($row = mysqli_fetch_array($result)) {
$callArray[] = array('phonenumber' => $row['phone_number'], 'id' => $row['phone_login_id']);
}
mysqli_close($con);
echo json_encode($callArray);
相关文章:
- 有没有一种方法可以防止img get请求使用css或js发生
- CORS-重定向到第二个GET正在接收的页面
- jQuery Ajax GET请求工作不正常
- 如何将PHP get查询转换为Meteor's HTTP.get()
- 返回/从Twit's客户端.get
- AngularJS错误:提供程序必须从$get工厂方法返回值
- 如何在router.get()方法中传递url作为参数
- 使用Javascript/JQuery获取JSON GET数据
- call()和apply()实际上是用来欺骗方法处理类似数组的对象的
- 如何使用php文件中的GET来获取我在.js文件中声明的变量
- Get方法获取csv文件的内容
- 什么'$.get和$.ajax之间的区别是什么
- I'我得到这个.get()在ember中未定义
- Babel编译错误:找不到模块核心js/library/fn/get迭代器
- Datatable get列值只给出前10行
- PHP $_GET with jQuery $.get call
- Rest api get call using jquery
- meteor HTTP "GET" call
- jQuery ajax get call
- Get a legitimate array from ajax & jquery call