Have simple button that makes ajax call to php page. Doesn't seem like the variables are being passed to the php page. I can hard code the value in the php page and it works. The values re populating to the button as well. What is happening here?
<button class='delete btn btn-danger' id="<?php print $row[id]; ?>" db_table="<?php print $db_table;?>"><i class="fe fe-trash-2"></i></button>

`

 $(function () {
  $('.delete').click(function(e){
	e.preventDefault()
    var el = this;
  
    // Delete id
    var deleteid = $(this).data('id');
	var db_table = $(this).data('db_table');
    var $tr = $(this).closest('tr'); //here we hold a reference to the clicked tr which will be later used to delete the row
    // Confirm box
    bootbox.confirm("Do you really want to delete the tract?", function(result) {
        
        if(result){
            // AJAX Request
            $.ajax({
				
                url: 'delete_do.php',
                type: 'POST',
                data: { id: deleteid, db_table: db_table },

                success: function(response){
					console.log(response);
					
					
                                            //on success, hide  element user wants to delete.
                    $tr.find('td').addClass('hilite').fadeOut(2000,function(){ 
                        $tr.remove();                    
                    }); 
					

                }
            });
        }
        
        });
   });
});`

    Your button's attributes need to be named data-id and data-db_table for jQuery's data method to pick them up. If you still want to use the button's id to be its ID in the document, you'd need to use this.id.

    jQuery: HTML5 data-* attributes

      Write a Reply...