下面是到目前爲止的代碼是我的工作,這將是一個評論系統,流量:我的jQuery Ajax表單不會發表
- 用戶填寫意見表
點擊提交, AJAX調用時和 張貼到PHP腳本
腳本可確定用戶應 輸入驗證碼形式
如果他們需要一個CA ptcha形成它發送 與有 消毒消息
一起迴響應。如果他們不需要驗證碼,它 進行消毒的消息,併成功響應
將其發送 回來,如果有錯誤它發回一個 錯誤消息。
如果成功,我們也該消息 添加到頁面
好自己的問題,到目前爲止是,當我點擊提交,重新加載的,而不是做Ajax調用的頁面,你看任何明顯的原因?
<script type="text/javascript">
$(document).ready(function() {
$('#load').hide();
//load facebox
$('a[rel*=facebox]').facebox()
});
// add comments
var messageArea = $('textarea#message');
$('input#submit-comment').click(function() {
// Store vars
var message = messageArea.hide().val();
var dataString = 'message=' + message + '&u=1';
//send comment to php
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
dataType: "json",
success: function (data) {
if (json.response == 'captcha') {
//they are mass posting so we need to give them the captcha form
// maybe we can open it in some kind of dialog like facebox
// have to figure out how I can pass the comment and user data to the captcha script and then post it
jQuery.facebox(function() {
jQuery.get('captchabox.php', function (data) {
jQuery.facebox('<textarea>' + data + '</textarea>')
})
})
alert('captcha');
} else if (json.response == 'error') {
// there was some sort of error so we will just show an error message in a DIV
// just an alert for testing purposes
alert('sorry there was an error');
} else if (json.response == 'success') {
alert('sucess');
// success append the sanitized-comment to the page
$('#comments').prepend(obj.comment);
};
}
})
return false;
});
</script>
<div id="container">
<div id="comments">
<!-- comments loop will be here from mysql results -->
<div class="comment">
<div class="date">
<span class="day-month"><?php echo $dayMonth; ?></span>
<span class="year"><?php echo $year; ?></span>
</div>
<span class="content"><?php echo stripslashes($message);?> <span class="time"><?php echo $datediff; ?></span></span>
<div class="clear"></div>
</div>
<!-- end comment loop-->
</div>
<div id="submission">
<form name="comment-submission">
<textarea id="message" name="message"></textarea>
<span class="limit">140</span>
<input type="submit" id="submit-comment" value=" " />
</form>
<div class="clear"></div>
</div>
</div>
UPDATE:
我的回報虛假增加了;就在ajax調用下面的點擊功能關閉之前,它在頁面上沒有任何變化,它仍然在點擊頁面上重新加載頁面,請任何幫助
我加了return false;插入下面的代碼中,它不會創建任何錯誤,但不會改變任何內容,它是否在錯誤的位置? – JasonDavis 2009-08-11 15:37:40