Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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 Underline.js Debounce无法使用Scroll正常工作_Javascript_Jquery_Ajax_Underscore.js - Fatal编程技术网

Javascript Underline.js Debounce无法使用Scroll正常工作

Javascript Underline.js Debounce无法使用Scroll正常工作,javascript,jquery,ajax,underscore.js,Javascript,Jquery,Ajax,Underscore.js,我正在尝试使用..debounceunderline.js函数来限制发送的AJAX POST请求的数量 我的代码应该只在用户滚动到页面底部并且我尝试使用.debounce等待2秒后再发送另一个请求时才执行AJAX。一旦我滚动到底部,AJAX就会正确执行,但是,如果我在到达底部后继续滚动,那么在2秒钟结束之前就会发送另一个AJAX请求 我也尝试过使用。油门 函数ajaxFunction(){ $.ajax({ 类型:“POST”, url:“搜索结果”, 数据:{skipAmount:$('.pr

我正在尝试使用
..debounce
underline.js函数来限制发送的AJAX POST请求的数量

我的代码应该只在用户滚动到页面底部并且我尝试使用
.debounce
等待2秒后再发送另一个请求时才执行AJAX。一旦我滚动到底部,AJAX就会正确执行,但是,如果我在到达底部后继续滚动,那么在2秒钟结束之前就会发送另一个AJAX请求

我也尝试过使用
油门

函数ajaxFunction(){
$.ajax({
类型:“POST”,
url:“搜索结果”,
数据:{skipAmount:$('.product box')。长度,搜索:search},
成功:功能(响应){
if(response!=null&&response.success){
$('#productcontent').append(response.responseText);
}
},
错误:函数(XMLHttpRequest、textStatus、errorshown){
如果(调试){
警报(XMLHttpRequest.responseText);
警报(文本状态);
警报(错误抛出);
}
}
});
}
函数debounceAjaxFunction(){{uu.debounce(ajaxFunction(),2000);}
$(窗口)。滚动(函数(){
if($(窗口).scrollTop()+$(窗口).height()==$(文档).height()){
去盎司函数();
}
})

您正在debounce参数中调用函数

    _.debounce(ajaxFunction(), 2000);
当您应该将其引用作为参数传递时

    _.debounce(ajaxFunction, 2000);
然后设置要从滚动函数调用的变量

   var debounceAjaxFunction = _.debounce(ajaxFunction, 2000);
此处的文档仅供参考,相关部分为

    var lazyLayout = _.debounce(calculateLayout, 300);