【发布时间】:2018-06-14 10:18:26
【问题描述】:
我不知道,不工作!
-我有用户的表格帖子
-
我想显示帖子而不使用 ajax 刷新页面
<form class="posting" method="POST" autocomplete="off" action="createpost.php"> <textarea name="text" class="textarea" ></textarea> <button class="btn-ajouter" type="submit" name="ajouter" value="ajouter">ajouter</button> </form>
//代码mysql同页
<?php
$stmt = $connect->query('SELECT post FROM publications
ORDER BY date_post DESC ');
while($row=$stmt->fetch() )
{
?>
<div class="allpost">
<?php
echo $row['post'].'<br>' ;
?>
</div>
<?php
}
?>
(jquery 存在于页面索引中) ()
<script>
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'createpost.php',
data: $('form').serialize(),
success: function () {
alert('form was submitted');
}
});
});
});
</script>
-但不工作
【问题讨论】:
-
编辑抱歉 $('form').on('submit'
-
什么不起作用?
-
“不工作”不是很有帮助......它有什么作用?你有错误吗?在屏幕上?在开发者工具控制台中?
-
不是错误控制台,也没有任何功能,只是我想要当用户发布没有刷新页面的显示帖子时
-
只是为了确认。您是否包含 jquery.js 文件? :P
标签: javascript php jquery mysql ajax