我应该在哪里放置超时以自动刷新页面



我正在尝试自动编写页面,以便我可以从数据库中检索最新数据。

我希望它将显示最新数据而不按任何内容显示,但是当我尝试输入新数据

时,它仍然不会显示。
$(document).ready(function() {
  load_data();
  function load_data(query) {
    $.ajax({
      url: "php/checkinhelper.php",
      method: "post",
      data: {
        query: query
      },
      success: function(data) {
        $('#result').html(data);
      }
    });
    window.setTimeout(100);
  }
  $('#search_text').change(function() {
    var search = $(this).val();
    if (search != '') {
      load_data(search);
    } else {
      window.setTimeout(100);
      load_data();
    }
  });
});

使用此:

$(document).ready(function() {
 load_data();
     function load_data(query) {
$.ajax({
  url: "php/checkinhelper.php",
  method: "post",
  data: {
    query: query
  },
  success: function(data) {
    $('#result').html(data);
  }
});
}
setTimeout(function(){ load_data() }, 100);
$('#search_text').change(function() {
var search = $(this).val();
if (search != '') {
  load_data(search);
} else {
  window.setTimeout(100);
  load_data();
}
});
});
        $(document).ready(function() {
        var elem = $('#search_text');
         setTimeout(() =>  elem.trigger('change'), 100);
          function load_data(query) {
            $.ajax({
              url: "php/checkinhelper.php",
              method: "post",
              data: {
                query: query
              },
              success: (data) => {
                  $('#result').html(data);
                  setTimeout(() =>  elem.trigger('change'), 100);
              }
            });
          }
          elem.change(function() {
            var search = $(this).val();
            if (search != '') {
              load_data(search);
            } 
          });
        });

最新更新