我想创建一个带有Ajax的评论系统。系统对post_comment.php进行ajax调用,在那里执行INSERT INTO并返回我需要的信息。Ajax调用崩溃页面
问题:脚本似乎不工作..它只是冻结我的页面,如果我等待它刷新页面8秒后。
<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>
(从谷歌控制台)唯一的错误我看到的是如下:最大调用堆栈大小超过了jQuery的 它在刷新过程中出现,然后消失
任何想法?提前致谢!
为什么'返回false;'这剂有什么影响? – Webdesigner
你可以添加你的html代码吗? @Webdesigner我认为这是为了避免在刷新页面 – linasmnew
时触发'post()'?用户点击按钮时是否是这样?你得到的错误意味着你超出了浏览器内存的限制 –