Php 更新记录而不刷新我的站点上的所有页面

Php 更新记录而不刷新我的站点上的所有页面,php,jquery,ajax,Php,Jquery,Ajax,如何在不刷新页面的情况下更新记录,我有一个系统,我想更新记录,在0和1之间更改其状态,打开或关闭功能。这是我打开或关闭它的窗体: <table class="tablesorter" cellspacing="0"> <thead> <tr> <th></th> <th>nane</th> <th>time

如何在不刷新页面的情况下更新记录,我有一个系统,我想更新记录,在0和1之间更改其状态,打开或关闭功能。这是我打开或关闭它的窗体:

<table class="tablesorter" cellspacing="0">
    <thead>
        <tr>
            <th></th>
            <th>nane</th>
            <th>time</th>
            <th>out</th>
            <th>enter</th>
            <th>
                <div align="center">admin</div>
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php $qu_req=mysql_query( "select * from `exit_request` where `date`='$date_now' order by id desc "); while($row_req=mysql_fetch_row($qu_req)){ ?>
        <tr>
            <td>
                <input type="checkbox">
            </td>
            <td><a href="show_exit_req.php?id=<?php print($row_req[0]); ?>" class="style9" onclick="NewWindow(this.href,'name','400','300','yes');return false"><?php print($row_req[1]); ?></a>
            </td>
            <td>
                <?php print($row_req[2]); ?>
            </td>
            <td>
                <?php print($row_req[6]); ?>
            </td>
            <td>
                <?php print($row_req[7]); ?>
            </td>
            <td>
                <div align="center">
                    <input name="<?php print(" chk_exit ".$row_req[0]); ?>" type="radio" value="0" <?php if($row_req[3]==0){print( 'checked');} ?>/>
                    <label>accept</label>
                    <input name="<?php print(" chk_exit ".$row_req[0]); ?>" type="radio" value="1" <?php if($row_req[3]==1){print( 'checked');} ?>/>
                    <label>not acept</label>
                </div>
            </td>
            <td>
                <input class="alt_btn" name="send" type="submit" value="رد الادارة" />
            </td>
        </tr>
        <? } ?>
    </tbody>
</table>

纳恩
时间
出来
进来
管理
/>
接受

您可以使用AJAX请求发布表单序列化内容,这在许多关于web中AJAX的教程中都可以看到,如果您需要在请求发送到PHP后更新表单内容,请尝试将JSON数据发送回表单并解析/更新表单,这将使您在不更改页面的情况下更新数据

它的过程取决于如何编写表单处理程序 对于AJAX请求,您可以参见文档中的示例, 另请参见表单处理的php端,以创建对话框

您可以找到示例或 网上有很多例子。
请参阅stackoverflow中的这个问题

这是我为一个小型聊天室编写的一些代码,用于提交新的聊天帖子:

$("#shout").keypress(function(e) {
        if(e.keyCode == 13) {
            $.ajax({
                url: "http://example.com/api.php",
                contentType: "text/html; charset=ISO-8859-1",
                data: {
                    action: "shout",
                    message: $("#shout").val()
                },
                success: function() {
                    $("#shout").val("");
                }
            })
        }
    });
只要在id为shout的输入字段上按Enter键,就会从输入字段中获取值,将其放入AJAX请求中,然后发送它。此外,在成功发送后,它会清除输入字段

action&data指定URL调用的GET参数(可能是)。但你也可以使用post,只需看一下的选项

希望这能让您了解如何向服务器发送数据

这是相应的代码,用于检查聊天室是否有新帖子,如果有,则加载它们

$(document).ready(function() {
            var lastShout;

            // This one gets the timestamp of the last chat entry
            $.ajax({
                url: "http://example.com/api.php",
                contentType: "text/html; charset=ISO-8859-1",
                async: false,
                data: {
                    action: "lastshout"
                },
                success: function(data) {
                    lastShout = data + 0
                }
            })

            // This one loads the content of the chatbox containing the posts
            $.ajax({
                url: "http://example.com/api.php",
                contentType: "text/html; charset=ISO-8859-1",
                data: {
                    action: "getshouts"
                },
                success: function(data) {
                    $("#shouts").html(data);
                }
            })

            // This will be executed every 5 seconds. It takes the timestamp from the beginning, asks the server again for the latest timestamp
            // and then checks if the response timestamp is higher than the timestamp from the beginning.
            // If so, he'll pull the chatbox content and put it into the specified div
            setInterval(function() {
                $.ajax({
                    url: "http://example.com/api.php",
                    contentType: "text/html; charset=ISO-8859-1",
                    async: false,
                    data: {
                        action: "lastshout"
                    },
                    success: function(data) {
                        data = data + 0
                        if(data > lastShout) {
                            lastShout = data;

                            $.ajax({
                                url: "http://example.com/api.php",
                                data: {
                                    action: "getshouts",
                                    init: 1
                                },
                                success: function(data) {
                                    if(data != "") {
                                        $("#shouts").html(data);
                                    }
                                }
                            })
                        }
                    }
                })


            }, 5000)
        })

删除行<代码>打印(“”)时重定向将不会发生。
$(document).ready(function() {
            var lastShout;

            // This one gets the timestamp of the last chat entry
            $.ajax({
                url: "http://example.com/api.php",
                contentType: "text/html; charset=ISO-8859-1",
                async: false,
                data: {
                    action: "lastshout"
                },
                success: function(data) {
                    lastShout = data + 0
                }
            })

            // This one loads the content of the chatbox containing the posts
            $.ajax({
                url: "http://example.com/api.php",
                contentType: "text/html; charset=ISO-8859-1",
                data: {
                    action: "getshouts"
                },
                success: function(data) {
                    $("#shouts").html(data);
                }
            })

            // This will be executed every 5 seconds. It takes the timestamp from the beginning, asks the server again for the latest timestamp
            // and then checks if the response timestamp is higher than the timestamp from the beginning.
            // If so, he'll pull the chatbox content and put it into the specified div
            setInterval(function() {
                $.ajax({
                    url: "http://example.com/api.php",
                    contentType: "text/html; charset=ISO-8859-1",
                    async: false,
                    data: {
                        action: "lastshout"
                    },
                    success: function(data) {
                        data = data + 0
                        if(data > lastShout) {
                            lastShout = data;

                            $.ajax({
                                url: "http://example.com/api.php",
                                data: {
                                    action: "getshouts",
                                    init: 1
                                },
                                success: function(data) {
                                    if(data != "") {
                                        $("#shouts").html(data);
                                    }
                                }
                            })
                        }
                    }
                })


            }, 5000)
        })