我想获得响应值,但单击按钮时没有响应; 为什么不在asp.net中提交表单?
我的代码:
<script type="text/javascript"> $(document).ready(function() { var options = { target: '#htmlTarget', dataType : 'json', url : 'Response.aspx', type : 'post', beforeSubmit: showRequest, success: function(msg){ alert(msg.txt + '\n\n' + msg.item); } }; $('#myForm1').ajaxForm(options); }); function showRequest(formData, jqForm,options) { return true; } $.fn.serializeNoViewState = function() { return this.find("input,textarea,select,hidden").not("[type=hidden][name^=__]").serialize(); } </script>
<form id="myForm1" runat="server"> <div id="htmlTarget"></div> <input type="text" name="txt"> <br> <input type="radio" name="item" value="A">A <input type="radio" name="item" value="B">B <input type="radio" name="item" value="C">C <input type="radio" name="item" value="D">D <br><br> <input type="submit" name="submitbtn" value="submit"> </form>
Response.cs
public partial class Response : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Expires = -1; if (Request.Form["txt"] != null && Request.Form["item"] != null) Response.Write("{txt: '" + Request["txt"] + "',item: '" + Request["item"] + "'}"); } }
答案 0 :(得分:0)
可能是因为id-mangling? ASP.NET认为它可以使用runat =“server”自由更改标记的ID。检查生成的HTML并检查表单的ID。
要解决这种特殊情况,您可以向表单添加一个不runat = server的包装元素,并将该表单作为目标。
<div id="myform_wrapper">
<!-- your form here -->
</div>
并以
为目标$("#myform_wrapper form")