简体   繁体   English

开机自检后刷新div

[英]Refresh div after POST

I'd like to refresh the div when a message is deleted from my cat How to make it work? 从猫中删除一条消息后,我想刷新div。如何使其正常工作?
I've put a piece of code. 我已经写了一段代码。
Thank you in advance. 先感谢您。

<script type="text/javascript">
        function deleteBox(id){
                              if (confirm("Confirnez-vous la suppression du message?"))
                              {
                                var dataString = 'id='+ id;
                                       $.ajax({
                                       type: "POST",
                                       url: "del.php",
                                       data: dataString,
                                       cache: false,
                                       success: function(result){
                                       if(result){

                                    // if data delete successfully
                                    if(result=='success'){  
                                    //Check random no, for animated type of effect
                                    var randNum=Math.floor((Math.random()*100)+1);
                                    if(randNum % 2==0){
                                    // Delete with slide up effect
                                    $("#chat-item_"+id).slideUp(1000);

                                    // HERE

                                    }else{
                                    // Just hide data
                                    $("#chat-item_"+id).hide(500);

                                    }
                                    }else{
                                    var errorMessage=result.substring(position+2);
                                    alert(errorMessage);
                                                }
                                            }
                                        }
                                   });
                                }
                            }
    </script>

Thank you for your help 谢谢您的帮助

In your del.php file you can run a query that gets all messages after you have deleted the one you want. 在您的del.php文件中,您可以运行一个查询,该查询在删除所需的消息后会获取所有消息。 Then echo the html to fill the div. 然后回显html以填充div。

Then on your Javascript side you can have it set the div's html to the data that is echoed back('results' variable). 然后在Javascript方面,您可以将div的html设置为回显的数据(“ results”变量)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM