2013-11-22 178 views
0

我有一個簡單的反饋表單,如下圖所示,它使用圖像作爲提交按鈕而不是標準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> 
+0

關閉Ajax調用之前成功功能之後刪除最後一個逗號,否則IE會拋出一個錯誤 – Razorphyn

回答

2

嘗試

缺少id="contact"form

<form name="contact" method="post" id="contact" action=""> 


或與您當前 form HTML

data: $('form[name="contact"]').serialize(), 
+1

我從來沒有意識到的ID =「接觸愚蠢的監督」。完美工作。非常感謝! – JamesT

+0

@JamesT歡迎高興幫助:) –

0

在這一行使用此:

data: $("#contact").serialize(), 

您選擇ID。

你應該改變這一行:

<form name="contact" method="post" action=""> 

<form id="contact" method="post" action=""> 
0
$("#contact").serialize() 

,如果你對你形成元素沒有設置 「id」 屬性這是行不通的。

剩下的就是好的,應該努力吧:)