0
我對這個淡出div有一個簡單的問題。我用facebox,之後提交,它顯示了一個錯誤,它會顯示此:AJAX淡入淡出
但是我想,要消逝,他們已經抓住了那個消息之後。在我的AJAX處理程序提交表單,這是PHP代碼:
<?php
require_once('....');
$form_name = $_GET['form_name'];
$form_comment = $_GET['form_comment'];
$date = date('Y-n-j');
$ip = $_SERVER['REMOTE_ADDR'];
if($form_name == '') {
echo("<div class='alert alert-error-x'>Don't forget to enter a name, as we need to identify who's commenting on this article!</div>");
} else if($form_comment == '') {
echo("<div class='alert alert-error-x'>Please do not leave the comment field blank, we want to know what you're saying!</div>");
} else {
mysql_query("INSERT INTO comment (id, articleid, name, comment, date, ip) VALUES (NULL,'{$_GET['id']}','{$form_name}','{$form_comment}','{$date}','{$ip}')");
// output comment
echo "<div class='alert alert-success-x'>Posted by <strong>$form_name</strong> on <strong>{$date}</strong>$form_comment</div>";
}
?>
這是什麼將要提交的輸出,在article.php:
<?php
$amount_get = mysql_query("SELECT * FROM comment WHERE articleid='" . mysql_real_escape_string($_GET['id']) . "'"); $comments = mysql_num_rows($amount_get);
$grab = mysql_query("SELECT * FROM comment WHERE articleid='" . mysql_real_escape_string($_GET['id']) . "'");
if (mysql_num_rows($grab)==0) {
echo "<div class='alert alert-note-x'>Sorry, it looks like their are no comments to be displayed, check back later!</div>";
}
while($row = mysql_fetch_array($grab)){
?>
<div id="new_comment"></div>
<div class="article-comment">
Posted by <b><?php echo $row['name'] ?></b> on <b><?php echo $row['date'] ?></b>
<br />
<?php echo $row['comment'] ?>
</div>
<?php } ?>
</div>
</body>
</html>
現在我嘗試添加core.js文件中的以下代碼位於我的網站上的krissales.com
$(window).bind("load", function() {
$('#new_comment').fadeOut(4000);
});
但是它沒有奏效。如果你想測試演示,請查看:http://www.krissales.com/#/media/30.This-is-a-new-article-for-Testing!
請問我做錯了什麼?
謝謝!
你爲什麼包含兩個jQuery庫? 1.4.4和1.4.2? – Ian
另外,你爲什麼使用3個不同的函數來運行代碼onload?你正在使用'$(window).bind(「load」,function(){});','jQuery(document).ready(function($){});'和$(init); ' – Ian
最後,問題在於您試圖在加載頁面時淡出'#new_comment'。但是直到DOM準備好之後才能發表評論。那麼你什麼時候真的想淡出評論呢?只需調用代碼即可在需要時將其淡入淡出......不要只將內容放入'document.ready'中 – Ian