Skip to content

Instantly share code, notes, and snippets.

Created October 7, 2020 09:19
What would you like to do?
let allComments = document.getElementById("all-comments");
let $name = $("#name");
let $comment = $("#comment");
$("#submit").on('click', function(){
//validation to prevent html tags being inputted input box
var reg =/<(.|\n)*?>/g;
if (reg.test($('#comment').val()) == true) {
var errorText ='HTML Tags Not Allowed';
var item =
username: $name.val(),
comment: $comment.val(),
postId: window.location.pathname,
type: "POST",
url: "[your-api-url-here]]",
data: JSON.stringify(item),
contentType: "application/json",
success : function(){
alert("Comment submitted successfully")
error : function(err){
alert("error in post" + JSON.stringify(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment