Contortor code
public JsonResult InsertComment(string description, int postID)
{
try
{
Comment comment = new Comment
{
Content = description,
DataCommented = DateTime.Now,
PostID = postID,
UserID = User.Identity.GetUserId()
};
db.Comments.Add(comment);
db.SaveChanges();
}
catch (Exception)
{
}
return Json(comment, JsonRequestBehavior.AllowGet);
}
Json Code
$(function () {
if (CommentInput.value != "") {
$.ajax({
type: 'GET',
url: '/Comment/InsertComment',
dataType: 'Json',
cache: false,
async: true,
data: { postID: CommentInput.getAttribute('data-postid'), description: CommentInput.value },
success: function () {
alert('oi');
}
});
CommentInput.value = "";
}
});
The comment is usually inserted, however it does not run alert
on sucess
, what is wrong?