我正在使用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