douqie1816 2016-08-11 05:13
浏览 40

当在AJAX,Jquery中使用GET更新数据库时,如何反映表上的更新

I have a table in my php file that is displayed using datatables. Upon clicking on a link in a row of the table, the database is updated using Jquery and GET AJAX. My database is getting updated, but table does not reflect the changes without a manual refresh. How do I make it possible, for the table values to reflect the changes immediately after the button is clicked. Code below:

$("#note").click(function(){
                var note = prompt('Enter note');

                if(note){ 

                    var xmlhttp = new XMLHttpRequest();
                    xmlhttp.onreadystatechange = function() {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
                        {
                            alert("Record updated");
                        }
                    };
                    xmlhttp.open("GET", "db_update.php?id="+id+"&note="+note, true);
                    xmlhttp.send();


                    /* $.get("db_update.php", { id: id[$index], note:note });  */
                }
                return false;

            });

Please advise.

  • 写回答

2条回答 默认 最新

  • duanmu5039 2016-08-11 05:16
    关注

    If you are using jquery datatable than this will help you:

    $('#table_id').DataTable().ajax.reload();
    

    otherwise make an ajax call to get the updated data from the database

    评论

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流