如何在不刷新页面的情况下从数据库(mysql)加载更新的数据? [关闭]

问题描述:

I want to show the data from database into a page. I am using AJAX and PHP. But there is not coming new updates data. If i refresh the page, then it is showing new updates data. Please give me some idea about it or some links for example.

Thanks advance everyone.

我想将数据从数据库显示到页面中。 我正在使用AJAX和PHP。 但是有 没有新的更新数据。 如果我刷新页面,那么它显示新的更新数据。 请给我一些关于它或某些链接的想法。 p>

谢谢大家。 p> div>

There is two reason for that either cache or your control will not wait until your response of ajax is come back. try this:

$.ajax({
    type: "POST",
    url: "<your file url>",
    data: {<arguments>},
    cache: false,
    async:false,
    success: function(data) {

    } 
});

This link may help you: http://www.w3schools.com/ajax/default.asp. You have to use AJAX code as it is. Change get file name as PHP file which you are using.

(Providing the code which you have used helps more.)

this is ajax code for updating result

 $(document).ready(function(){

             function search(){

                  var title=$("#search1").val();

                  if(title!=""){
                    $("#result").html("<img alt='ajax search' src='images/loader.gif'/>");
                     $.ajax({
                        type:"post",
                        url:"tes.php",////php file that access db data/////
                        data:"title="+title,
                        success:function(data){
                            $("#result").html(data);//.By using<ul id="result"></ul>in area where data has to be updated you can easily make over this.//
                            $("#search1").val("");///name of field through which you going to update//////
                         }
                      });
                  }      
             }

              $("#button").click(function(){
                   search();
              });

              $('#search1').keyup(function(e) {
                 if(e.keyCode == 13) {
                    search();
                  }
              });
        });