html+ashx 表单提交示例
程序员文章站
2024-02-26 13:52:58
1,sumbit表单提交 webform1.aspx源码: 复制代码 代码如下: <%@ page language="c#" autoeventwireup="tr...
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 + "&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;
}
}
}
}
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 + "&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;
}
}
}
}