如何在将数据插入数据库后移动页面


How can i move page after inserting data to database?

我正在制作一个公告板写作页面。

如果用户写下板的主题和内容并按下写按钮,它会转到服务器端并将数据插入数据库。之后,它将页面重新定位到公告板列表页面。直率、直率、轻松。

但问题在于同步。

有时,它会在插入数据之前重新定位页面。

因此,用户必须刷新页面才能更新视图。

如何在数据插入数据库后显示页面?

这是代码

                <title>Insert title here</title>
                <base href="<?php echo base_url(); ?>" />
                <link type="text/css" rel="stylesheet" href="formstyle.css">
                <link type="text/css" rel="stylesheet" href="buttonstyle.css">
                <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js">
                </script>
                <script type="text/javascript">
                    $(function(){
                        $("#writebutton").click(function(){
                            $.ajax({
                                type: 'POST',
                                url: "http://10.222.223.53/test1/index.php/home/writecomplete",
                                data: {
                                    'subject': $("#subject").val(),
                                    'content': $("#content").val()
                                },
                                success: function(msg){
                                   location.href="http://10.222.223.53/test1";
                                }
                            });
                        });
                    });
                </script>
            </head>
            <body>
                <!-- UI Object -->
                <fieldset>
                    <legend>
                        글쓰기 생성
                    </legend>
                    <div class="form_table">
                        <table border="1" cellspacing="0" summary="표의 요약을 반드시 넣어 주세요">
                            <tbody>
                                <tr>
                                    <th scope="row">
                                        제목
                                    </th>
                                    <td>
                                        <div class="item">
                                            <input type="text" style="width:320px" name="subject" title="레이블 텍스트" class="i_text" id="subject">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th scope="row">
                                        내용
                                    </th>
                                    <td>
                                        <div class="item">

                                            <textarea name="content" cols="50" rows="5" title="레이블 텍스트" class="i_text" id="content"></textarea>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <table>
                        <tr>
                            <td>
                                <span class="btn_pack medium" id="board_list"><a href="http://10.222.223.53/test1/index.php/home/gotolist">목록</a></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="btn_pack medium" id="write_complete"><input type="submit" value="작성완료" id="writebutton"></span>
                            </td>
                        </tr>
                    </table>
                </fieldset>
            </body>
        </html>

您的<form>元素未正确关闭。也检查你所有的其他标签。

您应该处理.submit(),而不是.click()

您不应该允许默认操作(提交)继续进行,这与您现有的代码有关。

试试这个:

     $(".form_table").submit(function(e){
       e.preventDefault();  // prevent default 'submit'
       $.ajax({
         // do your ajax stuff here.
       });     
     });