Prevent page refresh by sending a message with a normal click

my question is: Can I prevent the page from updating from this code.

As you can see, I am sending a message with a normal click, which I need because live does not support sending events.

jQuery('.verwijder').live('click', function() { 
    t=$(this);

    t.parents(".paneltbnote").animate({ opacity: 'hide' }, "slow",function(){
        t.parents(".wrappertbnote").remove();
        settbnotecounter();

        $db_tbnoteid = t.parents(1).children('.frmnoteid').val();

        $.post("tbnotesact.php", {
            noteid: $db_tbnoteid,
            actie: "verwijder",
            tijd: timestamp
        }, function(xml) {
            // hier nog iets doen
            berichtentoevoegen(xml);//feedback
        });//einde post methode

    });// einde callback animate methode

    return false;    
});//einde binding click event
0
source share
3 answers

try the following:

replace the first line with

jQuery('.verwijder').live('click', function(e) { t=$(this);

and replace return false; with

e.preventDefault();
+2
source

You return false in the click event, but unfortunately it will not stop the send action. If you have the option not to use a real-time event listener, you can always simply view the submit action using the bind () method.

jQuery('.verwijder').bind('submit', function() {
    /* everything as usual... */
    return false;
});

, , - , , , , .

$(function() {
    bind_submits();
    // Let pretend you have a link that adds forms to your page...
    $('#addForm').live('click', function() {
        add_form();
    });
});

function bind_submits() {
   // We need to unbind first to make we don't multi-bind 
   jQuery('.verwijder').unbind('submit').bind('submit', function() {
        /* everything as usual... */
        return false;
    });
}

function add_form() {
    /* do some stuff to add a form to your layout... */

    // Now reset all current 'submit' binds and add the new one...
    bind_submits();
}

, , live() ( , , livequery). , , .

jQuerying...

+2

Many times, if theres an error in the code, javascript never gets to the end of the function to "return false"; causing the page to reload. Clear the link now and see if any errors pop up.

0
source

All Articles