我有一个简单的反馈表单,如下所示,它使用图像作为提交按钮,而不是标准的 HTML 提交按钮。表单似乎已提交,但“data:”值始终为 NULL。我究竟做错了什么?代码如下。
表格:
<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>
最佳答案
尝试
表单
中缺少id="contact"
<form name="contact" method="post" id="contact" action="">
<小时/>
或将此与您当前的 form
html 一起使用
data: $('form[name="contact"]').serialize(),
关于javascript - Ajax 表单提交不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20142740/