javascript - 如何阻止 Jquery(Ajax)循环数据(包括 PHP)
问题描述
基本上,我在index.php文件中编写了一个脚本,该脚本通过调用 php 文件并从数据库中返回数据来从数据库中获取消息。然而!它循环了 2-3 次,有时还有 9 次!
有没有人能帮我查询一下!谢谢,对不起我的英语
<script>
$(document).ready(function() {
var flag = 0;
$.ajax({
type: "GET",
url: "assets/js/ajax/messages.php",
data: {
'offset': 0,
'limit': 6,
'user_id': <?php echo $User->Id(); ?>
},
success: function(data) {
$('#messages').append(data);
flag += 3;
}
});
$(window).scroll(function() {
if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
$.ajax({
type: "GET",
url: "assets/js/ajax/messages.php",
data: {
'offset': flag,
'limit': 3,
'user_id': <?php echo $User->Id(); ?>
},
success: function(data) {
$('#messages').append(data);
flag += 3;
}
});
}
});
});
解决方案
推荐阅读
- git - 是否有可能触发与作曲家的依赖关系的 GIT 差异
- node.js - 来自本机代码的 mocha 测试中未处理的拒绝
- c - 字符过多的字符串打印
- arrays - MATLAB:在数组旁边打印索引
- linux - 对非 root 用户使用终端快捷方式
- firebase - Firebase - 云函数返回未定义
- c# - 使用动态对象调用 Web Api 2 和 HttpClient
- node-red - 使用全局变量内容设置另一个变量时的全局值更改内容
- javascript - 如何从画布中的渲染元素获取副本?
- android - “无法解决:org.junit:junit:4.12”与 AndroidX 测试 JUnit