Hello @kartik,
From your description of being redirected to your homepage, but having no code in your ajax response sections to do this, I suspect that the element #add-comment is a submit button in your form.
If this is the case, then your form may be submitting at the same time the ajax code is running when you click the #add-comment submit button. This would explain the out of memory error as the ajax javascript is being expunged while the page redirects.
You would need to prevent your form from submitting, and let the success() or failure sections handle the next step .
One way to do this would be to change
$("#add-comment").on('click', function() {
...
to
$('#add-comment').on('click', function(event){
event.preventDefault();
...
or change the submit button from
<button type="submit" ...>Add comment</button>
to
<button type="button" ...>Add comment</button>
or change the form tag like this
<form onsubmit="return false;">
Hope this works!