我爲我的comment.php:AJAX提交上提交
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$('#reset_form').click(function() {
$('#name,#comment').val('');
});
$('#submit').click(function() {
var name = $('#name').val();
var comment = $('#comment').val();
$.ajax({
url: '../forms/comment_ajax.php?id=<?php echo $_GET['id']; ?>',
data: { form_name: name, form_comment: comment },
success: function(data) {
$('#new_comment').append(data);
$(document).trigger('close.facebox');
$('#new_comment').effect("bounce", { direction:'down', times:5 }, 300);
$('html,body').animate({scrollTop:0}, 2000, "easeOutQuart");
return false;
}
});
});
});
</script>
Name: <br />
<input type="text" id="name" class="userpass" maxlength="15"/><br /><br />
Comment: <br />
<textarea id="comment" rows="6" cols="75"></textarea><br /><br />
<input type="submit" name="submit class="button" value="Comment" />
<input type="reset" name="submit" value="Reset"/>
那麼這對我的AJAX:
<?php
require_once('../blog/inc/config.php');
$form_name = $_GET['form_name'];
$form_comment = htmlspecialchars($_GET['form_comment']);
$date = date('M jS Y | g:i a T');
$ip = $_SERVER['REMOTE_ADDR'];
if($form_name == '') {
echo("<div class='alert alert-error-x'>Don't forget to enter your 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='article-body-new'>
<div class='user'><b>$form_name</b> <span>says:</span></div>
<div class='comments'>
$form_comment <br /><p></p><br />
<p style='font-size:12px;'>Posted on <b><font size='0.8em'>$date</font></b></p>
</div>
</div>";
}
?>
我有這個工作的一個facebox JS,這是什麼將看起來像:http://screencloud.net/v/m9jR
但是,一旦你嘗試發佈,它不會發布的內容。我不斷點擊「評論」,但它不會執行。
我的全article.php頁面是在這裏:http://pastebin.com/DCHGR1Ly
請問你們是否知道它是什麼,我做錯了嗎?
成功回調裏面的返回錯誤是錯誤的,它需要走出去。 – 2013-03-19 23:39:58
這樣的事情:pastebin.com/eZiRX8bt請原諒我對編碼的無知,哈哈。 – TrippedStackers 2013-03-20 00:05:31