-2

So I have a few links that's values are stored in jQuery and then are used as a variable for the PHP file it calls. In that PHP file, it outputs the same exact links so the process can continue without refreshing the page. But, the second time clicking the links does not produce the jQuery POST ajax call to the php file.

Here is my jQuery code

jQuery('.wantedStatus').on('click', function(event)
{
    var anime_id = <?php echo $anime_id; ?>;
    var anime_list_entry_id = <?php echo $anime_list_entry_id; ?>;
    var wantedStatus = jQuery(this).tex   
    jQuery.post("/path/to/php/file/updateStatus_animelist.php", {firstParam : anime_id, secondParam : anime_list_entry_id, thirdParam : wantedStatus}, function(data) {
         //this is your response data from serv
         console.log(data);
         jQuery('#anime_list_update').html(data);
    });
    return false;
});

The links that activate this function.

<a href="javascript:void(0);" class="wantedStatus">Watching</a>
<a href="javascript:void(0);" class="wantedStatus">Plan to watch</a>
<a href="javascript:void(0);" class="wantedStatus">On hold</a>
<a href="javascript:void(0);" class="wantedStatus">Dropped</a>

Now these exact links are outputted from the updateStatus_animelist.php and so when they are clicked again, they don't work.

Maaz
  • 4,193
  • 6
  • 32
  • 50

1 Answers1

1

Because the elements are getting replaced on each call, you want to listen to click on either the parent or the document.

Please try:

jQuery(document).on('click', '.wantedStatus', function(event) {
  ...
});
vee
  • 38,255
  • 7
  • 74
  • 78