我正在使用jQuery表單插件來提交AJAX請求。這是使用此PHP腳本的簡單聯繫人:http://pastie.org/725652 - 唯一的驗證發生在PHP內部。使用PHP和jQuery表單插件的聯繫表格
這裏是我的Javascript代碼觸發整個事情:
$('#contactform').ajaxForm({
target: '#error',
beforeSubmit: function() {
$('#error').append('<p class="loading">Sending your message...</p>');
},
success: function() {
$('#error p.loading').fadeOut();
$('#error').fadeIn('slow');
}
});
不幸的是,它似乎並沒有工作。 PHP完美地工作,發送電子郵件並返回成功消息,但AJAX魔術由於某種原因不起作用。很顯然我想實現的是通過AJAX顯示PHP腳本通過AJAX返回的消息<div id="error />
我多次使用相同的腳本,從來沒有任何問題,現在我不明白爲什麼它不起作用。這是聯繫表單的標記。
<form id="contactform" class="group" method="post" action="submitemail.php">
<fieldset>
<div><label for="first-name">First Name</label>
<input type="text" name="first-name" value="Jeremy" /></div>
<div class="alt"><label for="last-name">Last Name</label>
<input type="text" name="last-name" value="Anderson" /></div>
<div><label for="email">E-mail <span>(never published)</span></label>
<input type="text" name="email" value="[email protected]" /></div>
<div class="alt"><label for="url">Website</label>
<input type="text" name="url" value="http://www.mywebsite.com" /></div>
<label for="question">Message</label>
<textarea name="question" id="" cols="30" rows="10">Thinking of something to say...</textarea>
<input type="submit" name="submit" id="submit" value="Send E-mail" />
<div id="error"></div>
</fieldset>
</form>
這裏是jQuery插件的代碼,如果它可以是任何幫助。 http://pastie.org/726175
如果有人可以看看整個事情,並提供一些技巧,爲什麼它不起作用,我會非常感激,提前致謝!
我開始認爲這只是一個簡單的錯字,但我通常會複製/粘貼以前項目中的所有腳本。通過這個看了十幾次,仍然無法發現它... – Justine 2009-12-03 20:23:40