Skip to content Skip to sidebar Skip to footer

How To Check If A Link Is Clicked Using Ajax/jquery

I am trying to delete a link without a page refresh, and I would like to jQuery to capture and send http request to a specific URL that does the deleting. But, for this to work, I

Solution 1:

You need to preventDefault.

 $(".delete").click(function(e){
   e.preventDefault()
   $.ajax({
   ..

Solution 2:

I don't know if I got you right here, but this may help you: http://api.jquery.com/event.preventDefault/

$( "a" ).click(function( event ) {
     event.preventDefault();

     //your code
}

Solution 3:

Prevent default behaviour of link using jQuery's preventDefault().

Having:

<a class='delete' href='http://site.com/delete.php?id=243'> deletethis </a>

Try:

$(".delete").click(function(e){
    e.preventDefault();
    $.ajax({
        type: "GET",
        url: "{{ path('http://site.com/delete.php?id=243'}}",
        cache: "false",
        dataType: "html",
        success: function(result){
            $(".success").append(result);
        }
    });
});

Post a Comment for "How To Check If A Link Is Clicked Using Ajax/jquery"