user2234992
user2234992

Reputation: 575

edit link with GET ajax call not working

I have a multiple lists of links..

echo '<td><a href="edit.php?pldid=' . mysql_result($query12, $i, 'pld_id') . '" id="editbt">Edit</a></td>';

I use ajax to use when I click this

 $("#editbt").click(function(event) {
    event.preventDefault();

     $.ajax({
            type: "GET",
            url: this.href,
            cache:false,
            success: function(response){
            alert(response);

            }
     });

});

My php file

<?php
include('connect.php');

 if (isset($_GET['pldid'])&& $_GET['pldid'])
 {
 echo $_GET['pldid'];


 }
?>

So when I click the link, I don't get the alert response, but I am directed to the page itself.

So when I click a link say edit.php?pldid=1234, I am directed this url edit.php?pldid=1234 with pldid printed.

So the isset($_GET['pldid'])&& $_GET['pldid'] holds true, But there is no ajax call..Hope I am clear.. thanks..

Upvotes: 0

Views: 121

Answers (1)

Barmar
Barmar

Reputation: 780724

Change your PHP to:

echo '<td><a href="edit.php?pldid=' . mysql_result($query12, $i, 'pld_id') . '" class="editbt">Edit</a></td>';

I changed id= to class= to prevent duplicate IDs.

Change the JS to:

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

     $.ajax({
            type: "GET",
            url: this.href,
            cache:false,
            success: function(response){
            alert(response);

            }
     });

});

I changed $("#editbt") to $(".editbt") to select by class instead of ID.

Upvotes: 1

Related Questions