Passing Variable to AJAX Call
Hi,
I am a new user to jQuery (and JavaScript in general). I have a scenario where I have a table of data that is generated from a SQL query. One column of my table is "Delete" where I have a button:
- <button id="delete_button" class="btn btn-danger btn-xs" type="button">Delete</button>
I am trying to create an AJAX call to another page which will actually perform the SQL query to delete the record. The "ID" of the record that needs to be deleted is known as $record_id (PHP).
My problem is that I do not know how to pass $record_id to the JavaScript handling the AJAX call. The code handling the AJAX call looks something like:
- $(document).ready(function() {
- $('#delete_button').click(function(event) {
- $.ajax({
- type : 'POST',
- url : 'delete.php',
- data : ??? // this should be something like id=$record_id
- dataType : 'json',
- encode : true
- })
- });
Any ideas would be greatly appreciated!
Thanks!