Javascript websocket正在工作但未更新我的html表

Javascript websocket正在工作但未更新我的html表,javascript,php,websocket,phpwebsocket,Javascript,Php,Websocket,Phpwebsocket,我有两个文件。php是我的表,它是用php从数据库中生成的,运行良好。然后编辑更新到数据库的页面,也可以正常工作。这两个文件都有用于websocket的javascript,可以正常工作。但在提交编辑表单后,我想使用websocket更新index.php表,但它不会更新表。下面是我的两个文件 index.php <!DOCTYPE html> <html> <head> <meta charset="utf-8"&g

我有两个文件。php是我的表,它是用php从数据库中生成的,运行良好。然后编辑更新到数据库的页面,也可以正常工作。这两个文件都有用于websocket的javascript,可以正常工作。但在提交编辑表单后,我想使用websocket更新index.php表,但它不会更新表。下面是我的两个文件

index.php

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <title>Names</title>
        <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body><br>

    <table width="100%" class="table table-striped table-bordered table-hover mytables" id="dataTables-example">
        <thead>
            <tr>
                <th> name</th>
            </tr>
        </thead>
        <tbody >
            <?php
                if(!empty($table_data)){
                    foreach($table_data as $key=> $value){
                        $name = $value['name'];
            ?>
            <tr class="odd gradeX">
                <td><?php echo $name; ?></td>
            </tr>
            <?php
                    }
                }
            ?>

        </tbody>
    </table>

    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
    <script>
    $(document).ready(function() {
        //create a new WebSocket object.

        var wsUri = "ws://localhost:9000/server.php";   
        websocket = new WebSocket(wsUri); 

        // connection is open 
        websocket.onopen = function(ev) { 
            console.log('socket is open');
        }
        // Message received from server
        websocket.onmessage = function(ev) {
            $('#dataTables-example').load ('index.php', '#dataTables-example');

        };

        websocket.onerror   = function(ev){ 
            console.log('socket is error');
        }; 
        websocket.onclose   = function(ev){ 
            console.log('socket is closed');
        }; 


    </script>

    </body>
    </html>

名字

名称 $(文档).ready(函数(){ //创建新的WebSocket对象。 var wsUri=“ws://localhost:9000/server.php”; websocket=新的websocket(wsUri); //连接已打开 websocket.onopen=函数(ev){ log(“套接字打开”); } //从服务器收到的消息 websocket.onmessage=函数(ev){ $(“#数据表示例”).load('index.php',“#数据表示例”); }; websocket.onerror=函数(ev){ log('socketis error'); }; websocket.onclose=函数(ev){ log(“套接字已关闭”); };
edit.php:

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <title>names</title>
        <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body><br>

    <form accept-charset="UTF-8" role="form" id="search" name="search" action="edit.php" method="post">

        <div class="form-group">
            <input type="text" id="name" name="name" class="form-control">
        </div>

        <center><button class="btn  btn-success btn-md" type="submit" name="submit" id="submit">Save</button></center>

    </form>

    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
    <script>
    $(document).ready(function() {

        $('#submit').click(function(){
            send_message();
        });

        //create a new WebSocket object.
        var wsUri = "ws://localhost:9000/server.php";   
        websocket = new WebSocket(wsUri); 

    });

    function send_message(){
        websocket.send('update tables');
        console.log('sending to message to index'); 
    }


    </script>

    </body>
    </html>

名字

拯救 $(文档).ready(函数(){ $(“#提交”)。单击(函数(){ 发送消息(); }); //创建新的WebSocket对象。 var wsUri=“ws://localhost:9000/server.php”; websocket=新的websocket(wsUri); }); 函数send_message(){ send('updatetables'); log('将消息发送到索引'); }
您有没有收到任何错误?没有错误,我可以在index.php控制台日志中看到由edit.php触发的服务器返回。因此这两个文件通信良好