我正在使用jquery ajax进行php mysql插入。现在我想添加一个效果:如果插入成功或没有,也会加载从ajax process page
淡入淡出的HTML。如何修改?谢谢。php插入返回数据与jquery ajax和淡入淡出效果
的index.php
<script type="text/javascript">
$(function(){
$("#submit").click(function(){
var formvalue = $("#content").val();
var url = 'submit=1&content=' + escape(formvalue);
$.ajax({
type: "POST",
url: "2.php",
data: url,
success: function(){
$("#content").val('');
$("#comment").fadeIn(1000, function() {
$("#comment").html(html);
});
$("#comment").fadeOut(1000, function() {
$("#comment").html('');
});
}
});
return false;
});
});
</script>
<form id="form" action="2.php" method="post">
<textarea name="content" id="content" cols="30" rows="3"></textarea> <br />
<input type="submit" id="submit" name="submit" value="Add comment" />
</form>
<div id="comment"></div>
2.PHP
<?php
$connection = mysql_connect('localhost', 'root' , 'root') or die(mysql_error());
$selection = mysql_select_db('my_content', $connection);
if(isset($_POST['submit'])){
$content = $_POST['content'];
$ins = mysql_query("INSERT INTO msg (content) VALUES ('$content')");
echo 'insert success';
}else{
echo 'failed';
}
?>
请问你能否小心地改述一下你的问题。我似乎无法理解你要去哪里.. – 2011-05-09 13:50:27
@PENDO,当我在'index.php'中插入某些内容时,数据将发送到'2.php'。那么我想从'2.php'中得到'insert success'或'failed'这个词,并显示在'index.php'中的'div#comment'中。返回的单词可能具有淡入淡出效果。我的意思是,'插入成功'这个词首先在'div#comment'中淡出,然后消失。谢谢 – cj333 2011-05-09 14:03:30
看到我的'解决方案'下面(没有足够的字符在这里) – 2011-05-09 14:41:10