I have an AJAX request in jquery that posts todo items to mysql.
I have the rows displaying from the database and I have the form input working but
I don't know how to do the delete and edit functions.
I realize I need an id on each row for SQL to know which row to
delete from MySQL. I added the database id field to the mysqli query.
Now the id field got added to the AJAX response.
I don't want it printing to the web page for the user to see it.
How can I access it while hiding it on each row so that I can input the id when I want to either delete it or edit that row?
The AJAX response sends all 4 fields in the response in firebug but
I am still only printing the 3 fields out on the page. See demo page.
janisrough.dyndns.biz/todo1.html
This is my delete.php handler.
require_once('global.inc.php');
$mysqli = new mysqli($dbhost,$dbuser, $dbpass, $dbname,$dbport);
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
$sql = "DELETE FROM task WHERE id =
".$mysqli->real_escape_string($_POST['id'])."";
$result = $mysqli->query($sql);
$result->close();
}//end i
$mysqli->close();
}
this is my Jquery function to delete the checked rows.
$('#response tbody').on( 'click', 'tr', function () {
var tr = this;
$.ajax( {
type:"POST",
url: 'ajax/delete.php',
data: '',
success: function () {
t.fnDeleteRow( tr );
}
} );
} );
What goes in the data line? THANKS,