0

I am trying to prevent an AJAX post when a user clicks on a link.

So far, I have this, but preventDefault() is not working:

$('.link-class').live('click', function (event) { 
    console.log("live----Stopped?!?!"); 
    event.preventDefault(); 
    return false; 
 });

1 Answer 1

1

Too many things could be going on, link to the target page.

In general, if intercepting click doesn't work, try intercepting mousedown and mouseup as well, as some pages trigger off of those, instead.

$('.link-class').live ('click mousedown mouseup', function (event) { 
    console.log ("live----Stopped?!?!"); 
    event.preventDefault (); 
    return false; 
 } );
Sign up to request clarification or add additional context in comments.

3 Comments

yup tried "click mousedown mouseup" but no luck. ajax post is still happening.
Like I said, too many things could be happening to list. Link to the target page and/or provide a fully self-contained example of the problem. Beware that if the site is a Google app, they are notorious for FUBAR'd javascript that is very hard to userscript.
You are definitely correct. The JS is very cryptic. I was just hoping that I can prevent post requests regardless of what or how they are doing it. as far as the direct target page, well I am trying to write a user script that will make you confirm that you really want to like something on FB. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.