Getting Variables on AJAX POST Process

I’m trying to POST something via AJAX but have a little problem which I couldn’t solve.

I have a PHP foreach loop and a delete function. Basically, I want to delete some items in this foreach with AJAX POST request. I can make POST thing but can not get ID value. ID value is too important for me, ’cause system should know which data will delete.

You can find my PHP code below:

<tbody>
 <?php foreach($contactMessages as $c) { ?>
  <tr>
   <td><?php echo $c['name']; ?></td>
   <td><?php echo $c['subject']; ?></td>
   <td><a data-toggle="modal" data-target="#delete" id="delete"></td>
  </tr>
 <?php }?>
</tbody>

And here is my JavaScript code:

<script type="text/javascript">
    $('#delete').click(function() 
     { 
      $.ajax({
      url: '<?php echo site_url('admin/messages/delete/'); ?>',
      type: 'POST',
      data: {'submit':true},
     });  
     });
</script>

As I said, I have to POST unique ID but couldn’t find how to get it via JavaScript. Thanks in advance.


Source: ajax

Leave a Reply