Php 完成表单提交操作,无需重新加载页面
我希望表单数据在提交后发送到我的php文件,而不加载php文件页面。然后发送的数据在处理后必须在提要中淡出。有人能帮我吗?以下是我的密码: home.php:Php 完成表单提交操作,无需重新加载页面,php,jquery,html,ajax,forms,Php,Jquery,Html,Ajax,Forms,我希望表单数据在提交后发送到我的php文件,而不加载php文件页面。然后发送的数据在处理后必须在提要中淡出。有人能帮我吗?以下是我的密码: home.php: <script> $(document).ready(function(){ $('#content').load('feeds.php'); }, 1000 ); </script> <?php //after connecting to my database and a
<script>
$(document).ready(function(){
$('#content').load('feeds.php');
}, 1000
);
</script>
<?php
//after connecting to my database and all
$sql = mysql_query("SELECT * FROM `posts` ORDER BY `post_id` DESC");
while($row = mysql_fetch_assoc($sql)) {
echo '<div id="post">' . $row['post'] . '</div><br />';
}
?>
<div id="content"></div>
#内容:
<script>
$(document).ready(function(){
$('#content').load('feeds.php');
}, 1000
);
</script>
<?php
//after connecting to my database and all
$sql = mysql_query("SELECT * FROM `posts` ORDER BY `post_id` DESC");
while($row = mysql_fetch_assoc($sql)) {
echo '<div id="post">' . $row['post'] . '</div><br />';
}
?>
<div id="content"></div>
没有别的了
请帮我修改这个代码!作为回报,谢谢你 最好的解决方案应该是JQuery和AJAX。使用AJAX将数据发送到任何页面,并根据响应淡出数据。以下是示例实现:
jQuery(function($){
$("#post").submit(function(){
$.ajax({
url: $(this).attr("action"),
data: $(this).serialize(),
success: function(){
alert("data sent");
}
});
return false;
});
把这个从
<form id="post" action="post.php" method="POST">
<textarea name="post" width=300 height=150></textarea>
<input type="submit" value="Post" id="submit">
</form>
我没有测试它,但它应该是这样的。
希望对您有所帮助。查看本页右侧。你可以看到很多描述你需要什么的链接。确定它确实使用了@Fred ii-@AkashRaj Reload属性;它在5分钟前就消失了;)我的错误。我在想别的事情。@Htmlin.com发布了一个片段。尝试围绕这一点构建您的解决方案。
$('#submit').click(function(event) {
event.preventDefault(); /* Stops default form submit on click */
var post = $('#post').val();
$.ajax({
url: "post.php?",
data: 'post=' + post,
type: "POST",
success: function(data){
$('#content').empty();
$('#content').load('feeds.php');
}
});
});