使用Ajax发布HTML页面的一部分

using Ajax to post part of the HTML page

本文关键字:一部分 HTML Ajax 发布 使用      更新时间:2023-09-26

-已编辑-

你好,

我有一个包含两个表格的页面,我只想使用邮寄方式发送第二个表格。

该表格具有检查有效日期、电子邮件等的有效功能。

我想在不离开页面的情况下发送第二张表单,只发送第二份表单。据我所知,AJAX是可行的,但我不知道如何执行。

以下是代码的示例

客户端

<body>
<div> ....
<form id='f1'>....</form>
<script> //validation functions, at the end of the main validation function there is a            //code that submits the second form , the one i intend to send.
</script>
<form id='f2'  action='http://mysite/goToMyHandler.cs...>
...some input controls...
<input type='button' value='send' onclick='executeValidation();'>
</form>
</body>

服务器端

myHandler.cs:

保存中的数据

Response.Write('Form has been successfully sent');

感谢

使用jQuery和serializeObject。

你会这样做:

$.post($('#myform').attr('action'),$('#myform').serializeObject(),function(r){alert('successfully did it');});