html+ashx 表單提交示例
更新時間:2014年03月22日 18:02:05 作者:
這篇文章主要介紹了html+ashx 表單提交的具體實現(xiàn),需要的朋友可以參考下
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源碼:
復(fù)制代碼 代碼如下:
<%@ 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源碼:
復(fù)制代碼 代碼如下:
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 源碼:
復(fù)制代碼 代碼如下:
<!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源碼:
復(fù)制代碼 代碼如下:
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;
}
}
}
}
相關(guān)文章
asp.net 中靜態(tài)方法和動態(tài)方法調(diào)用的區(qū)別實例分析
動態(tài)方法,在使用時需要先創(chuàng)建實例,才能調(diào)用實例方法,而靜態(tài)方法則不需要,直接使用即可。2013-06-06.net?core利用PdfSharpCore操作PDF實例教程
操作pdf是我們?nèi)粘i_發(fā)中經(jīng)常遇到的功能,下面這篇文章主要給大家介紹了關(guān)于.net?core利用PdfSharpCore操作PDF實例的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2022-12-12asp.net GridView和DataList實現(xiàn)鼠標移到行行變色
在設(shè)計頁面添加了DataList控件后,我在使用DataList綁定數(shù)據(jù)時是通過單元格來綁定的,因此鼠標效果就在源代碼頁面去實現(xiàn)2009-02-02Silverlight融合ajax實現(xiàn)前后臺數(shù)據(jù)交互
兩年前Silverlight 還未起名,故事發(fā)生在WPF/E 的年代里。07年8月在中軟實習(xí)時,我承擔(dān)起了在. Net 中嵌入WPF/E 的任務(wù),目的是增強用戶體驗。2009-05-05ASP.NET?MVC5網(wǎng)站開發(fā)咨詢管理的架構(gòu)(十一)
這篇文章主要介紹了ASP.NET?MVC5網(wǎng)站開發(fā)咨詢管理的架構(gòu),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-09-09ASP.Net Core3.0中使用JWT認證的實現(xiàn)
這篇文章主要介紹了ASP.Net Core3.0中使用JWT認證的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01