Last active
August 29, 2015 14:02
-
-
Save aroc/a0175669102bec44ea28 to your computer and use it in GitHub Desktop.
SideComments listening to events example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Listen to "commentPosted", and send a request to your backend to save the comment. | |
| // More about this event in the "docs" section. | |
| sideComments.on('commentPosted', function( comment ) { | |
| $.ajax({ | |
| url: '/comments', | |
| type: 'POST' | |
| data: comment, | |
| success: function( savedComment ) { | |
| // Once the comment is saved, you can insert the comment into the comment stream with "insertComment(comment)". | |
| sideComments.insertComment(comment); | |
| } | |
| }); | |
| }); | |
| // Listen to "commentDeleted" and send a request to your backend to delete the comment. | |
| // More about this event in the "docs" section. | |
| sideComments.on('commentDeleted', function( commentId ) { | |
| $.ajax({ | |
| url: '/comments/' + commentId, | |
| type: 'DELETE', | |
| success: function( success ) { | |
| // Do something. | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, this needs a few updates:
commentPostedneeds to inject acomment.idbefore runninginsertComment(comment).commentDeletedevent needs to receive acommentobject, notcommentId.Thanks for the great work!