Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. commentForm.addEventListener('submit', function(e){
  2.         e.preventDefault();
  3.         if(newComment.value == ''){
  4.             alert('please fill out a full comment');   
  5.         }else{
  6.             var form = document.forms.namedItem("commentForm");
  7.             var formData = new FormData(form);
  8.             var message = newComment.value;
  9.             var req = new XMLHttpRequest();
  10.             req.open("POST", "comments", true);
  11.             req.onload = function(event){
  12.                 if(req.status == 200){
  13.                     console.log("Upload!");
  14.                     createComment(message);
  15.                 }else
  16.                     console.log("error" + req.status);
  17.             }
  18.             req.send(formData);
  19.         }
  20.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement