가 완료 될 때까지 이전 이벤트의 실행을 방지하는 방법 : 목록에 새 항목을 삽입하고 마지막 하나를 제거마지막 호출이 나는이 jQuery를 이벤트가
$('#button-next').bind('click', function() {
$.ajax({
type: "GET",
dataType: "json",
url: 'index.php?route=product/category/display&cat=any&limit='+p+',1',
cache: false,
success: function(data) {
var text = data.output;
goForward('scroller', text);
p++;
}
});
});
합니다. 문제는 사용자가 버튼을 너무 빨리 클릭하기 시작하면 엉망이되는 것입니다. 마지막 통화가 끝나기 전에 새로운 통화를 막을 수있는 방법이 필요합니다.
function process() {
$.ajax({
type: 'GET',
dataType: 'json',
url: 'index.php',
cache: false,
data: {
route: 'product/category/display',
cat: 'any',
limit: p + ',1'
},
success: function(data) {
var text = data.output;
goForward('scroller', text);
p++;
// we rebind the click event once again
$('#button-next').one('click', process);
}
});
}
대신에 '$ ('# button-next '). clic k (function()'$ ('# button-next')) 하나 ('click', function()'. 이것은 unbind를 불필요하게 만들고 한 줄을 절약합니다. – topek
@topek, 훌륭한 아이디어. 귀하의 의견을 고려하여 내 게시물을 업데이트했습니다. 이것을 지적 해 주셔서 감사합니다. –