Html 当数据库中的值更改时,如何刷新页面的一部分(Codeigniter)?

Html 当数据库中的值更改时,如何刷新页面的一部分(Codeigniter)?,html,css,ajax,codeigniter,Html,Css,Ajax,Codeigniter,我正在用codeigniter做一个在线食品配送系统。这是显示订单状态的部分。它在数据库中得到更新 新的 准备好的 在路上 交付 首先,您应该准备HTML页面: <td> <button type="button" class="btn" id="ch_button"></button> </td> 如果你按照这个指令做每一步,你就会得到你想要的。下一轮轮到我了。使用ajax更新网页的任何部分我不知道如何做。.JQuery:$.aja

我正在用codeigniter做一个在线食品配送系统。这是显示订单状态的部分。它在数据库中得到更新


新的
准备好的
在路上
交付

首先,您应该准备HTML页面:

<td>
    <button type="button" class="btn" id="ch_button"></button>
</td>

如果你按照这个指令做每一步,你就会得到你想要的。下一轮轮到我了。

使用ajax更新网页的任何部分我不知道如何做。.JQuery:
$.ajax({url:'controller/method',data:variable,method:'post'})。完成(函数(response){if(response){//update page part};})。失败(函数(){alert('ajax已经失败);})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
     $(function(){

         update_button(); 
     })  

 function timerss(){
            var s1= new Date();
            var c1= s1.setSeconds(s1.getSeconds() + 2);  // update in 2seconds

        var x1= setInterval(function() { 
            var n1= new Date().getTime();        
            var d1= c1 - n1;

            if (d1< 0) {

                clearInterval(x1);            
                update_button();
            }
        }, 1000);

 };

function update_button(){
         $.ajax({                                        
                url:"/index.php/controller1/method1", 
                method:"POST",
                data: null 
            }).done(function(ans) { 

                if (ans == 0) {
                    $('#ch_button').attr('style','background-color: #FAA0C7;color:#000;cursor: context-menu;');          
                    $('#ch_button').html('New');
                    timerss();
                }
                else if (ans == 3) {
                    $('#ch_button').attr('style','background-color: #6ED1FB;color:#000;cursor: context-menu;');
                    $('#ch_button').html('Ready');
                    timerss();
                }
                else if (ans == 5) {
                    $('#ch_button').attr('style','background-color: #FEE609;color:#000;cursor: context-menu;');
                    $('#ch_button').html('On the way');
                    timerss();
                }
                else if (ans == 6) {
                    $('#ch_button').attr('style','background-color: #7FFFD4;color:#000;cursor: context-menu;');
                    $('#ch_button').html('Delivered');
                }
            }).fail(function (){

                alert('Ajax has been failed.');
            });
}   
</script>
<?php
class Controller1 extends CI_Controller {

    public function __construct() {
        parent::__construct(); 
    }

    public function method1() {
       // get value of $order_current_status
        $order_current_status = 5; // for example

        echo $order_current_status;
    }
}