0

ページを更新せずにレコードを更新するにはどうすればよいですか。レコードを更新し、そのステータスを 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>

更新コード

if(isset($_POST['send'])){
    $qu=mysql_query("select * from `exit_request` ");
    while($row=mysql_fetch_row($qu)){
        $id=$row[0];
        $chk_str="chk_exit".$id;
        $chk_str=$$chk_str;
        //if($chk_str==1)
        mysql_query("update `exit_request` set `accept`='$chk_str' where id=$id");
        print('<meta http-equiv="refresh" content="0;URL=index.php" />');
    }
}
4

4 に答える 4

0

Web の AJAX に関する多くのチュートリアルで見られるように、AJAX 要求を使用してフォームのシリアル化されたコンテンツを投稿できます。要求が PHP に送信された後にフォームのコンテンツを更新する必要がある場合は、JSON データをフォームに送り返し、解析/更新してみてください。これにより、ページを変更せずにデータを更新できます。

手順は、フォーム処理をどのように記述するかによって異なります。AJAX 要求に対してjQueryを使用できます。例についてはドキュメントを参照してください。また、フォーム処理の php 側についてはjson_encodeを参照してください。ダイアログを作成するためのjQuery UIも参照してください。

于 2012-05-28T06:43:54.777 に答える
0

ここで例を見つけるか、これを参照してください 。ネットにはたくさんの例があります。 stackoverflow でこの質問を参照してください

于 2012-05-28T06:54:02.400 に答える
0

これは、新しいチャット投稿を送信するために、小さなチャットボックス用に書いたコードです。

$("#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 の叫びで Enter キーを押すとすぐに、入力フィールドから値が取得され、AJAX 要求に入れられて送信されます。また、正常に送信された後、入力フィールドをクリアします。

action と data は、URL 呼び出しの GET パラメータを指定します (これはhttp://example.com/api.php?action=shout&message=valueFromInputFieldGoeshereになります)。しかし、post を使用することもできます。.ajax()のオプションを見てください。

これにより、サーバーにデータを送信する方法についてのアイデアが得られることを願っています。

これは対応するコードで、チャットボックスに新しい投稿が行われたかどうかを確認し、投稿された場​​合はそれらを読み込みます。

$(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)
        })
于 2012-05-28T08:04:51.827 に答える
0

http://api.jquery.com/jQuery.ajax/

于 2012-05-28T06:50:08.693 に答える