html+ashx 表单提交示例

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了html+ashx 表单提交示例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1,sumbIT表单提交

WebForm1.aspx码:
复制代码 代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="NETFormDemo.ashx.WebForm1" %>

<!DOCTYPE htML>

<html XMlns="http://www.w3.org/1999/xhtml">
<head >
<;meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">

</script>
</head>
<body>
<form id="form1" action="submitForm.ashx" >
<div>
<input type="submit" value="提交" />
</div>
</form>
</body>
</html>

submitForm.ashx源码:
复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NETFormDemo.ashx
{
/// <summary>
/// submitForm 的摘要说明
/// </summary>
public class submitForm : IHttpHandler
{

public void PRocessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}

public bool IsReusable
{
get
{
return false;
}
}
}
}

2,ajax提交
HtmlPage1.html 源码:
复制代码 代码如下:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title></title>
<script src="test1.js" type="text/javascript"></script>
<script src="jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function add(url) {
VAR A = $("#a1").val();
var B = $("#b1").val();
$.ajax({
url: "ashx/add.ashx?i=" + A + "&amp;j=" + B,
data: {
num1: A,
num2: B
},
dataType: "html",
success: function (result) {
}
});
}
</script>
</head>

<body>
<form id="form1" runat="server">
<input type="text" id="a1" />
<input type="text" id="b1"/>
<input type="button" onclick="add()"/>
<label id="lb"></label>
</form>
</body>

</html>

add.ashx源码:
复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NETFormDemo.ashx
{
/// <summary>
/// Login 的摘要说明
/// </summary>
public class LOGin : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int First = Convert.ToInt32(context.Request.Params["i"]);
int sec = Convert.ToInt32(context.Request.Params["j"]);

int res = first + sec;
context.Response.Write(res);
context.Response.Write("fdd ff");

}

public bool IsReusable
{
get
{
return false;
}
}


}
}

脚本宝典总结

以上是脚本宝典为你收集整理的html+ashx 表单提交示例全部内容,希望文章能够帮你解决html+ashx 表单提交示例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:ashxashxhtml