PM 시스템을 만들고 있는데, 현재 시스템에 별표 메시지를 추가하고 있습니다 (사용자가 메시지에 별표를 표시 할 수 있도록).1 분 내에 요소가 클릭되는 횟수를 제한하려면 어떻게해야합니까?
사용자가 주연을 남기고 메시지의 별표를 제거하는 것이 계속 반복되면 서버를 망칠 것입니다 (호스트는 프로세스가 멈출 때까지 503 오류를 둡니다). 메시지에 별표를 표시하려면 별표를 클릭하여 별표를 표시하거나 다시 클릭하여 별표를 제거하는 것처럼 간단합니다.
이 분 내 시간의 X 번호를 클릭 한 후 오류가 팝업 만들기보다는 많이 클릭되는 것을 방지하거나하는 방법이 있나요? 스타를 클릭하면 AJAX 요청을 전송하고 데이터베이스를 업데이트하므로 서버 오버로드를 방지 할 수 있습니다. 당신이 그것을 성급하게 할 때, 그것은 똑같은 일을합니다.
1 분 내에 별표를 클릭하면 오류가 표시되는 jQuery 방법이 있습니까?
이 제 기능이 출연 있습니다 : 사전에
function addStar(id) {
$('#starimg_' + id).removeClass("not_starred").addClass("starred");
$('#star_' + id).attr({
'title': 'Starred',
'onclick': 'removeStar(' + id + ')'
});
$.get('tools.php?type=addstar', {id: id}, function(data) {
if(data=='true') { // tools.php will echo 'true' if it is successful
alertBox('The message has been starred successfully', 2500);
}
else { alertBox('An error has occurred. Please try again later.'); }
});
}
function removeStar(id) {
$('#starimg_' + id).removeClass("starred").addClass("not_starred");
$('#star_' + id).attr({
'title': 'Not starred',
'onclick': 'addStar(' + id + ')'
});
$.get('tools.php?type=removestar', {id: id}, function(data) {
if(data=='true') { // tools.php will echo 'true' if it is successful
alertBox('The message has been unstarred successfully', 2500);
}
else { alertBox('An error has occurred. Please try again later.'); }
});
}
감사합니다!
http://stackoverflow.com/questions/5031501/how-to-rate-limit-ajax-requests 당신이 사용할 수 – SuitedSloth
: http://stackoverflow.com/questions/7804312/remy- sharps-function-throttler – SuitedSloth
@juand : 감사합니다. – Nathan