Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仅刷新表PHP_Javascript_Php_Mysql - Fatal编程技术网

Javascript 仅刷新表PHP

Javascript 仅刷新表PHP,javascript,php,mysql,Javascript,Php,Mysql,因此,此页面正在从数据库中重新编码位置。(此部分正在工作)。 但无论我做什么,我的表格都不会刷新。我不想只刷新表格本身就刷新整个页面 我只是想在某个x时间刷新表格,但我做的每件事都不起作用,我尝试了很多次,但我都想不出来 <?php $id = (isset($_GET['id'])) ? ((int) $_GET['id']) : 0; // if we got input from user convert to numbers else set to 0 if($id

因此,此页面正在从数据库中重新编码位置。(此部分正在工作)。 但无论我做什么,我的表格都不会刷新。我不想只刷新表格本身就刷新整个页面 我只是想在某个x时间刷新表格,但我做的每件事都不起作用,我尝试了很多次,但我都想不出来

<?php
    $id = (isset($_GET['id'])) ? ((int) $_GET['id']) : 0; // if we got input from user convert to numbers else set to 0
    if($id <= 0) // the number must be greater than 0
        exit();

    require_once("db.php"); // connect to the database
?>
<!DOCTYPE html>
<html>
<head>

    <title>Hello User</title>
    <meta charset="UTF-8">
    <script async defer src="https://maps.googleapis.com/maps/api/js?language=iw&region=IL&key=AIzaSyDyXdL4cZlxo3ldIuvi6_HpZa2jhj7iOU0&callback=initialize"
  type="text/javascript"></script>
    <style>#map { height: 600px; width: 1500px}</style>


<script>

  $(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        $('#tablediv').load('googlemaps.php');
        setInterval(refreshTable, 1000);
    }
</script>

</script>
</head>
<body>
    <h1>Tracking Program</h1>
    <div id="map"></div> <!-- map div !-->
    <div id="tablediv">
    <table style="background-color: red;" id="tableid" >
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Id</th>
                <th>Phone Number</th>
                <th>Address</th>
            </tr>
        </thead>
        <tbody>

<?php
// get all data from the table and print it
if($result = $db->query("SELECT FirstName, Lastname, Id, Phone,Address FROM details WHERE RowNum ORDER BY RowNum DESC LIMIT 1")) {
    while($row = $result->fetch_assoc()) {
?>
            <tr>
                <td><?=$row['FirstName']; ?></td>
                <td><?=$row['Lastname']; ?></td>
                <td><?=$row['Id']; ?></td>
                <td><?=$row['Phone']; ?></td>
                <td><?=$row['Address']; ?></td>

            </tr>
<?php
    }

    $result->close(); //free the result
}
?>


        </tbody>
    </table>
</div>
</body>

<script type="text/javascript">
var marker, map; // make them global to get access from other functions

function initialize(myLatlng) {
    myLatlng = myLatlng || "<?php include("lastloc.php"); ?>";
    myLatlng = myLatlng.split(",");
    myLatlng = new google.maps.LatLng(myLatlng[0], myLatlng[1]);

    var mapOptions = {
        zoom: 11,
        center: myLatlng
    }
    map = new google.maps.Map(document.getElementById('map'), mapOptions);

    marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'מיקום אחרון'
    });
}

// ajax request to load last location
function lastLocation(){
    var xmlhttp;


    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){


        if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
            // method 1
            //initialize(xmlhttp.responseText);

            // method 2
            myLatlng = xmlhttp.responseText.split(",");
            myLatlng = new google.maps.LatLng(myLatlng[0], myLatlng[1]);
            marker.setPosition(myLatlng); // update the position of the marker on the map
            map.setCenter(myLatlng); // update the center of the map
        }
    }
    xmlhttp.open("GET", "lastloc.php?id=<?=$id; ?>", true);
    xmlhttp.send();
}

// timer to refresh the last location we have in the database
setInterval(lastLocation, 5000);


</script>

</html>
<?php
    // close the connection to the datebase
    if($db)
        $db->close();
?>

你好,用户
#地图{高度:600px;宽度:1500px}
$(文档).ready(函数(){
刷新表();
});
函数刷新表(){
$('#tablediv').load('googlemaps.php');
设置间隔(刷新表,1000);
}
跟踪程序
名字
姓
身份证件
电话号码
地址
变量标记,映射;//使它们成为全局的,以便从其他功能访问
函数初始化(myLatlng){
myLatlng=myLatlng | | |“;
myLatlng=myLatlng.split(“,”);
myLatlng=new google.maps.LatLng(myLatlng[0],myLatlng[1]);
变量映射选项={
缩放:11,
中心:myLatlng
}
map=new google.maps.map(document.getElementById('map'),mapOptions);
marker=新的google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“מיקםאחרו”
});
}
//加载最后位置的ajax请求
函数lastLocation(){
var-xmlhttp;
xmlhttp=新的XMLHttpRequest();
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
//方法1
//初始化(xmlhttp.responseText);
//方法2
myLatlng=xmlhttp.responseText.split(“,”);
myLatlng=new google.maps.LatLng(myLatlng[0],myLatlng[1]);
marker.setPosition(myLatlng);//更新标记在地图上的位置
setCenter(myLatlng);//更新地图的中心
}
}
open(“GET”,“lastloc.php?id=”,true);
xmlhttp.send();
}
//刷新数据库中最后一个位置的计时器
设置间隔(最后位置,5000);

这可能是因为实际操作表的是PHP,而不是AJAX。您需要使用API方法,所以在这个页面上没有PHP,另一个页面(PHP)以JSON或XML格式提供所有值。然后这个页面上的JavaScript将其转换为对象并写入相关的表格单元格。这可能是因为PHP才是实际操作表格的工具,而不是AJAX。您需要使用API方法,所以在这个页面上没有PHP,另一个页面(PHP)以JSON或XML格式提供所有值。然后,此页面上的JavaScript将其转换为对象并写入相关的表单元格。