我有一個簡單的反饋表單,如下圖所示,它使用圖像作爲提交按鈕而不是標準HTML提交按鈕。表單似乎提交,但「data:」值始終爲NULL。我究竟做錯了什麼?下面的代碼。Ajax表單提交不起作用
形式:
<div id="theResponse" class="ContactForm"></div>
<label><span class="footer_text_2"> Email</span> </label>
<br />
<form name="contact" method="post" action="">
<input name="txtEmail" type="text" class="contact" id="txtEmail" value="" />
<span class="footer_text_2"> Message</span>
<textarea name="txtComment" cols="18" rows="3" class="contact" id="txtComment"></textarea>
<input name="Id" type="hidden" id="Id" value="1"/>
<input name="input" type="image" id="ContactSubmit" src="images/btn_send.png" width="60" height="22"/>
</form>
jQuery代碼:
$(document).ready(function(){
//Bind the click event for the login button
$("#ContactSubmit").bind("click", function(){ });
// The click event for button click
$('#ContactSubmit').click(function() {
$.ajax({
type: "POST",
url: "MyAccount/ProcessContactForm.asp",
data: $("#contact").serialize(),
cache: false,
dataType: "html",
success: function(responseText){
$("#theResponse").html(responseText);
},
});
return false;
});
});
</script>
關閉Ajax調用之前成功功能之後刪除最後一個逗號,否則IE會拋出一個錯誤 – Razorphyn