当前位置: 移动技术网 > IT编程>开发语言>.net > html+ashx 表单提交示例

html+ashx 表单提交示例

2017年12月12日  | 移动技术网IT编程  | 我要评论

ip138天气,耳濡目染的近义词,不锈钢板网

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;
}
}


}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网