我正在用jquery ajax制作一个php-mysql插件。现在我想添加一个效果:如果插入成功与否,还将从ajax进程页面
加载带有fadein和fadeout的html。如何修改?谢谢
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 ;
}
?>