.NET实例(伪异步表单提交,实现无刷新表单(含文件)提交) 兼容IE 火狐 基于LGPL开源 谢绝转载
时间:2011-03-06 来源:humble
后台代码
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
var name = context.Request["username"];
var age = context.Request["age"];
var address = context.Request["address"];
var file = context.Request.Files[0].FileName;
var ret = name + " " + age + " " + address + " " + file;
WriteForm(context, ret);
}
public bool IsReusable {
get {
return false;
}
}
public void WriteForm(HttpContext context,string str)
{
string method = context.Request["callback"];
string hs = "<script>void " + method + "('" + str + "');</script>";
context.Response.Write(hs);
context.Response.Flush();
context.Response.Close();
context.Response.End();
}
}
源代码下载: /Files/humble/WebSite1.zip
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
var name = context.Request["username"];
var age = context.Request["age"];
var address = context.Request["address"];
var file = context.Request.Files[0].FileName;
var ret = name + " " + age + " " + address + " " + file;
WriteForm(context, ret);
}
public bool IsReusable {
get {
return false;
}
}
public void WriteForm(HttpContext context,string str)
{
string method = context.Request["callback"];
string hs = "<script>void " + method + "('" + str + "');</script>";
context.Response.Write(hs);
context.Response.Flush();
context.Response.Close();
context.Response.End();
}
}
注:
public void WriteForm(HttpContext context,string str) 此方法不必修改可以自定义
运行效果
源代码下载: /Files/humble/WebSite1.zip
相关阅读 更多 +