jqueryappend和JSON多次激发

jqueryappend和JSON多次激发,jquery,Jquery,今天,我需要一些帮助 我有一个HTML5移动应用程序,当用户点击键盘上的GO按钮时,搜索结果将以无限滚动加载 每件事都很有魅力!,除了每次当用户重新开始并进行新的搜索时,结果都会被加载两到三次,或者只是添加以前搜索中缺少的结果,这意味着我无法清除结果列表 我尝试了jQuery的所有功能,比如删除、清空列表、以任何方式绑定提交处理程序,这都是不可能的。每次加载和附加新结果或混合时。我做错了什么 我的问题是,如何清除或删除该列表,以便处理程序每次只触发一次新的空列表 搜索页面 <form id

今天,我需要一些帮助

我有一个HTML5移动应用程序,当用户点击键盘上的GO按钮时,搜索结果将以无限滚动加载

每件事都很有魅力!,除了每次当用户重新开始并进行新的搜索时,结果都会被加载两到三次,或者只是添加以前搜索中缺少的结果,这意味着我无法清除结果列表

我尝试了jQuery的所有功能,比如删除、清空列表、以任何方式绑定提交处理程序,这都是不可能的。每次加载和附加新结果或混合时。我做错了什么

我的问题是,如何清除或删除该列表,以便处理程序每次只触发一次新的空列表

搜索页面

<form id="search">
<fieldset data-icon="search">
<input type="search" id="gos" placeholder="What are you looking for?" />
</fieldset>
</form>
这里是加载结果的代码

   $.fn.scrollPagination = function() {



var settings = { 
nop     : 10,
offset  : 0,
error   : 'No More Posts!',
delay   : 0
}

return this.each(function() {       

$this = $(this);
$settings = settings;
var offset = $settings.offset;
var busy = false;

// Custom messages based on settings
$initmessage = '';

// Append custom messages and extra UI
$this.append('<div class="content"></div><div class="loading-bar">'+$initmessage+'</div>');

function getData() {

$('.animation_image').show();

// Post data to ajax.php
$.post('http://', {
action        : 'scrollpagination',
number        : $settings.nop,
offset        : offset,
}, function(data) {

var output='';
for (var i in data.users) {
output+="<li>" + data.users[i].firstName + " " + data.users[i].lastName + "--" + data.users[i].month+"</li>";
}




// Change loading bar content (it may have been altered)
$this.find('.loading-bar').html($initmessage);
$('.animation_image').hide();

// If there is no data returned, there are no more posts to be shown. Show error
if(output === "") { 
alert($settings.error);
$this.find('.loading-bar').html($settings.error);   
}
else {

// Offset increases
offset = offset+$settings.nop; 
$this.find('.content').append(output);   


// No longer busy!  
busy = false;
}   

});

}   

getData(); // Run function initially

$('#items').scroll(function() {

if($(this)[0].scrollHeight - $(this).scrollTop() === $(this).outerHeight() && !busy)  {
// Now we are working, so busy is true
busy = true;                    
// Tell the user we're loading posts
$this.find('.loading-bar').html('<img src="static/images/ajax-loader.gif">');
// Run the function to fetch the data inside a delay
setTimeout(function() {
getData();
}, $settings.delay);
}   
});

});

}
这里是结果页面

<ul id="content"></ul>

谢谢。

请不要委派给文档,或者在离开该区域时解除活动的绑定。委托给你离开页面时被删除的内容,以便自动清理。你好,凯文,谢谢,但我如何才能这样做来委托他清理所有>li的活动。我对jQuery比较陌生。我认为您根本不需要授权。您应该在搜索页面pageCreate或pageInit事件中绑定submit事件。您正在使用jQuery Mobile,对吗?一次解决一个问题。您最大的问题是提交事件触发多次。如果修复submit事件并不能修复它,那么这个问题的后半部分应该是第二个问题
<ul id="content"></ul>