I am trying to create a comment system with ajax. The system makes an ajax call to post_comment.php where it does a INSERT INTO and returns the info I need.
Problem: the script seems not to work.. it just freezes my page, and if I wait it refreshes the page after 8 seconds.
<script type="text/javascript">
function post()
{
var comment = document.getElementById("content").value;
if(comment)
{
$.ajax
({
type: 'post',
url: 'templates/post_comment.php',
data:
{
content:content,
user_id:<?php echo $_SESSION['id']; ?>,
brand_id:<?php echo $_SESSION['brand_id']; ?>,
ticket_id:<?php echo $_GET['unique_id']; ?>
},
success: function (response)
{
console.log('okay response');
document.getElementById("all_comments").innerHTML=response+document.getElementById("all_comments").innerHTML;
document.getElementById("content").value="";
document.getElementById("username").value="";
}, error: function() {
alert("There was an error. Try again please!");
}
});
}
return false;
}
</script>
the only error (from google console) i see is the following: maximum call stack size exceeded jquery it appears during the refresh, and then it disappears
Any ideas? Thanks in advance!