我正在使用http://malsup.com/jquery/form/
中的jQuery表单插件在我的测试页面上它运行得很好,但对于一些在我的最后一页上有一堆动态生成的项目,表单提交到我的ajax php然后像传统的html表单一样重定向我。
以下是每种表单的html:
<form class="comform" action="ajax/comment.php" method="post">
<input type="hidden" name="postid" value="<? echo $id;?>">
<textarea name="comment" cols="50" rows="2" class="commenttext" id="amazing"></textarea>
<input type="submit" value="+" />
</form>
和正在使用的脚本:
<script>
$(document).ready(function() {
$('.comform').ajaxForm(function() {
alert("working, change this later");
});
});
</script>
正如我所说,这是通过ajax提交到comment.php,但在具有多个评论框的真实页面上,它也会重定向到ajax / comment.php
答案 0 :(得分:0)
您可能需要在回调中return false
以阻止浏览器的默认操作。
请参阅插件的API文档here。
请注意,ajaxSubmit
需要return false
。当然,这只是在您手动调用提交函数时,但它可能表示该插件默认情况下不会阻止事件传播。