How to make jquery table which is refreshing itself in every 10 secs?

前端 未结 3 2052
后悔当初
后悔当初 2021-01-16 17:47

I am making admin portal, where admin can see the total number of current booking, for this we have to refresh table every 10 sec automatically and there wi

3条回答
  •  温柔的废话
    2021-01-16 18:07

    Try below code: - Use setInterval

    1st Step :

    You should create one common function which will fetch all data form Database as below.

    function fetchData(){
        $(".data-contacts-js tbody").empty(); // this will remove all .
    $.get("http://localhost:8080/Hotels/reservation/getAllBookingDetails", function(data) {
                            $.each(data, function(i, contact) {
                                $(".data-contacts-js").append(
                                    "" + contact.custId + "" +
                                    "" + contact.custName + "" +
                                    "" + contact.custMobile + "" +
                                    "" + contact.custEmail + "" +
                                    "" + contact.custAddress + "" +
                                    "" + contact.Date + "" +
                                    "" + contact.Time + ""
                                    );
                            });
                        });
    }
    

    Step 2: Make function which will call function automatically in every 10 sec. using SetInterval as below.

    $(document).ready(function(){
        setInterval(function(){
            fetchData();
        },10000);  // this will call your fetchData function for every 10 Sec.
    
    });
    

    Step 3: Make one event function for refresh button click event and put this function in .ready() function.

    $('#fetchContacts').click(function() {
         fetchData();
    });
    

提交回复
热议问题