tags:

views:

39

answers:

1

The Jquery load function don't stop if there is multiple click on the links in the menu.

The jquery code looks like:

$(document).ready(function(){

$(".menu_rfr").unbind("click").click(function() {
$("#main").html('<img src="img/spin.gif" class="spin">');
location.replace($(this).attr('rel'));
});

function handleClick() {
$(this).unbind("click");
$("#main").html('<img src="img/spin.gif" class="spin">');
$("#main").load($(this).attr('rel'), function() {

    // reactivate it after some loading has completed
    $(this).click(handleClick);        
});         
}
$(".menu_clickable").click(handleClick);
});

You can see the sample page at link text

How can I prevent users clicks if the DIV content is not loaded completely and never ending DIV loading?

A: 

The $(this) in the handleClick isn't referring to the element.

Here's some code that is one way to fix this. I think it will work, I'm not at a computer that I can test it on though.

$(document).ready(function(){

$(".menu_rfr").click(function() {
    $("#main").html('<img src="img/spin.gif" class="spin">');
    location.replace($(this).attr('rel'));
});

function handleClick(ele) {
    $(ele).unbind("click");
    $("#main").html('<img src="img/spin.gif" class="spin">');
    $("#main").load($(this).attr('rel'), function() {
        // reactivate it after some loading has completed
        $(ele).bind('click',function(event){bindClick(event.target);});        
    });        
}

function bindClick(ele){
    $(ele).bind('click',function(event){
        handleClick(event.target);
    });
}

$(".menu_clickable").each(function(){
    bindClick($(this));
});
});
Brant
No, it does not work. It staks after load "spin.gif" and do not load other part of the DIV :(
Sergio