Is it even possible to bulk delete items from a server with ajax? I am at a complete loss here.
I am trying to run an each function to pull the url id for each item on my server and then plug it into a ajax delete type call. This makes sense to me, but I am still new at programming and I feel like I could be miles off.
Any amount of insight on this would be a huge help. Thanks.
$('#delete-friends').on('click', function() {
$.ajax({
type: 'GET',
url: 'http://rest.learncode.academy/api/johnbob/friends',
success: function(friends) {
var scratchFriend = $.each(friends, function(i, friend) {
var friendID = (friend.id);
console.log(friendID);
$ajax({
type: 'DELETE',
url: 'http://rest.learncode.academy/api/johnbob/friends/'
friendID ','
success: function() {
console.log('Friend Deleted Successfully!');
}
});
});
}
});
});
#delete-friends {
position: absolute;
top: 10%;
left: 70%;
font-size: 20px;
border-radius: 10px;
}
<div class="friendForm">
<button id="delete-friends">Delete all of the friends?</button>
<h4>Be a friend</h4>
<p>Name:
<input type='text' id='name'>
</p>
<p>Age:
<input type='text' id='age'>
</p>
<button id="add-friend">Join us Friend</button>
</div>