【发布时间】:2019-01-02 18:46:56
【问题描述】:
我的 view.php 页面通过获得一个唯一的序列号来自另一个页面。现在在我的 view.php 页面中,我想显示来自charts.php 的指定序列号数据。我自己完成了我的代码。它正在获取数据。但不是选择的序列号。我该如何解决这个问题
view.php
<?php
if(isset($_GET['serial'])){
$serial = $_GET['serial'];
?>
<html>
<div class="container" id="output"></div>
</html>
<script>
$(document).ready(function(){
function getData(){
$.ajax({
type: 'POST',
url: 'charts.php',
success: function(data){
$('#output').html(data);
}
});
}
getData();
setInterval(function () {
getData();
}, 1000); // it will refresh your data every 1 sec
});
</script>
charts.php
<?php
$sql = mysqli_query($con,"SELECT * FROM criminal WHERE rand = '$serial'");
while($row = mysqli_fetch_assoc($sql)){
?>
请帮忙。
【问题讨论】:
-
你永远不会向 PHP 脚本发送
$serial。 -
如何在 ajax 的 php 脚本中发送 $serial 变量
-
AJAX 请求需要一个
data:属性。 -
数据:$("#whatever_your_form_id_is").serialize()
-
卫生署!我看到了“POST”并思考了形式。我的错。没有注意到顶部的查询字符串。