Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 滚动时如何自动加载数据_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 滚动时如何自动加载数据

Javascript 滚动时如何自动加载数据,javascript,jquery,ajax,Javascript,Jquery,Ajax,滚动时如何自动加载数据。如果没有页面刷新,则应加载数据 $(文档).ready(函数(){ $(“#数据表格”)。关于('submit',函数(e){ var form_data=$(this).serialize(); $.ajax({ 类型:“POST”, url:'index.php/Profile\u cntrl/supplier\u communication', 数据:表格数据, 成功:功能(数据){ 向下滚动(); var message=$(“#messagee”).val(

滚动时如何自动加载数据。如果没有页面刷新,则应加载数据


$(文档).ready(函数(){
$(“#数据表格”)。关于('submit',函数(e){
var form_data=$(this).serialize();
$.ajax({
类型:“POST”,
url:'index.php/Profile\u cntrl/supplier\u communication',
数据:表格数据,
成功:功能(数据){
向下滚动();
var message=$(“#messagee”).val();
$(“#聊天记录”)。追加(“”+消息+”

”); $('#messagee').val(''); }, 错误:函数(){ 警报(“失败”); } }); e、 预防默认值(); }); 向下滚动(); 函数scrollDown(){ $('.msg_container_base')。设置动画({ scrollTop:$('.msg_container_base').prop(“scrollHeight”) }, 200); } });
您可以这样做

这只是一个例子。请根据您的要求进行修改

$(窗口)。滚动(函数()
{

如果($(document).height()在窗口向下滚动后加载数据:

$(window).scroll(function (){
      if($(document).height() <= $(window).scrollTop() + $(window).height())
      {
        LoadData();
      }
});

    function LoadData(){
   //No need submit a form
     var form_data = $('#data_form').serialize();
                $.ajax({
                    type: "POST",
                    url: '<?php echo base_url(); ?>index.php/Profile_cntrl/supplier_communication',
                    data: form_data,
                    success: function(data) {
                        var message = $("#messagee").val();
                            $('#chat_log').append('<div class="row msg_container base_sent active"><div class="row msg_container base_receive"><div class="col-md-12 col-xs-12"><div class="messages msg_receive"><p><a>' + message + '</a></p></div></div></div></div>');
                            $('#messagee').val('');
                    },
                    error: function() {
                        alert('failed');
                    }
                });
                e.preventDefault();
    }
$(窗口)。滚动(函数(){

如果($(document).height()在我的代码中如何集成有点混乱…如果可能,请修改我的代码@Manjeet@siddum请更改要在服务器上发送的URL和数据,如pageSize或pageOffset`$.ajax({type:'post',url:'here set you api url',data:query//here您需要将查询发送到服务器,`您的代码不起作用。主要问题是没有将值插入到数据库中,并且在将数据插入到数据库@Govind时,应该自动从上到下滚动
 $(window).scroll(function ()
    {
      if($(document).height() <= $(window).scrollTop() + $(window).height())
      {
        loadmore();
      }
    });

    function loadmore()
    {
      var val = document.getElementById("row_no").value;
      $.ajax({
      type: 'post',
      url: 'get_results.php',
      data: {
       getresult:val
      },
      success: function (response) {
      var content = document.getElementById("all_rows");
      content.innerHTML = content.innerHTML+response;

      // We increase the value by 10 because we limit the results by 10
      document.getElementById("row_no").value = Number(val)+10;
      }
      });
    }
$(window).scroll(function (){
      if($(document).height() <= $(window).scrollTop() + $(window).height())
      {
        LoadData();
      }
});

    function LoadData(){
   //No need submit a form
     var form_data = $('#data_form').serialize();
                $.ajax({
                    type: "POST",
                    url: '<?php echo base_url(); ?>index.php/Profile_cntrl/supplier_communication',
                    data: form_data,
                    success: function(data) {
                        var message = $("#messagee").val();
                            $('#chat_log').append('<div class="row msg_container base_sent active"><div class="row msg_container base_receive"><div class="col-md-12 col-xs-12"><div class="messages msg_receive"><p><a>' + message + '</a></p></div></div></div></div>');
                            $('#messagee').val('');
                    },
                    error: function() {
                        alert('failed');
                    }
                });
                e.preventDefault();
    }