Skip to content

Instantly share code, notes, and snippets.

@blaisethomas
Last active January 19, 2016 20:22
Show Gist options
  • Save blaisethomas/0a3ac4b7cf0d764e1706 to your computer and use it in GitHub Desktop.
Save blaisethomas/0a3ac4b7cf0d764e1706 to your computer and use it in GitHub Desktop.
JQuery AJAX Delete for lab on friday (slightly hacked)

#The Delete button on index page (à la "jquery AJAX")

include jquery

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"> </script>

add button to loop. Notice id is set to Mongo ID

<li><div class="btn btn-danger glyphicon glyphicon-trash" id="<%= candies[i].id %>"></div></li>

Just a little bit of AJAX:

<script type="text/javascript">
$('.btn').click(callDelete)
function callDelete(){
	console.log(this.id)
	$.ajax({
	    url: '/candies/' + this.id,
	    type: 'DELETE',
	    success: function(result) {
	        //console.log(result)
	        //hack for forcing page reload
	        location.reload()
	    }
	})
};


</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment