Hello there, I am working on a small CRM for a Racing Team. I am creating a page where they can write a post and delete the posts at their liking. I am using ajax to do all the data transmission in the background to prevent page refresh. The whole posting is done, working and easy. But I can't get my head around deleting a single or multiple posts.
Here is the context:
When the client sings in the admin.php page, I am generating a <form> which contain a <fieldset> per post title.
At the top of the code you can see I have a delete post button to trigger the ajax code to delete the single or multiple posts. How would I go about using JQuery AJAX to do a simple PHP:
foreach ( $_POST['select_post'] as $postID )
{
$query = "DELETE FROM news WHERE id = $postID";
mysqli_query( $dbc, $query )
or die ( 'Could not delete the post.' );
}
Will doing this work? Is my data: { select_post : postID } automatically an array?
$('#post_list').submit( function () {
var postID = $('.select_post').val();
$.ajax({
type: 'POST',
url: 'delete_post.php',
data: { select_post : postID }
}).success( function () {
alert('deleted');
});
});
Hello there, I am working on a small CRM for a Racing Team. I am creating a page where they can write a post and delete the posts at their liking. I am using ajax to do all the data transmission in the background to prevent page refresh. The whole posting is done, working and easy. But I can't get my head around deleting a single or multiple posts.
Here is the context:
When the client sings in the admin.php page, I am generating a <form> which contain a <fieldset> per post title.
At the top of the code you can see I have a delete post button to trigger the ajax code to delete the single or multiple posts. How would I go about using JQuery AJAX to do a simple PHP:
Will doing this work? Is my data: { select_post : postID } automatically an array?
NEVERMIND!!! I just had to create an array and pass it to my delete.php file.
Thanks to myself :P