我无法调用ajax函数,如下所示(index.php):
Validators.pattern(..)
我的按钮点击在这里(index.php):
<script type="text/javascript">
$('.show_more').on('click',function (e){
$.ajax({
type:'POST',
url:'gallery_controller.php',
success:function(html){
$('.content').append(html);
}
});
});
这是我的php脚本(gallery_controller.php):
<form action="" method="post">
<button type="submit" class="show_more" name="next">Next</button>
</form>
它似乎什么都不做,我已经尝试了一些东西,似乎没有任何工作..我想知道ajax甚至可以在我的服务器上运行..我是一个完整的菜鸟。
答案 0 :(得分:1)
您需要该按钮的表单吗? 如果您将按钮包装成W3C有效性问题的表单就可以了,您只需将按钮类型属性从type =“submit”更改为type =“button”。
答案 1 :(得分:0)
请检查以下完整代码。我想“e.preventDefault();”你的代码中缺少。
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="" method="post">
<button type="submit" class="show_more" name="next">Next</button>
</form>
<div class="content">
</div>
<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<script>
$('.show_more').on('click',function (e){
e.preventDefault();
$.ajax({
type:'POST',
url:'gallery_controller.php',
success:function(html){
$('.content').append(html);
}
});
});
</script>
</body>
</html>