Your code doesn't work because rightNav.bind('click');
does not actually bind the click
event to your function.
The syntax for bind
(in your case) is bind(event, callback)
.
So you could either:
a) Give a name to your function so you can assign it back, such as:
var f = function() { if(index <= listLength - 2){ ...
rightNav.click(f);
And then you assign it back with:
rightNav.bind('click', f);
b) Ignore click when ajax is already loading:
else {
//rightNav.unbind('click');
if (rightNav.loading) {
return;
}
rightNav.loading = true;
...
success: function(data){
rightNav.loading = false;
...