asp.net+jquery.form实现图片异步上传的方法(附jquery.form.js下载)

本文实例讲述了asp.net+jquery.form实现图片异步上传方法分享给大家供大家参考,具体如下:

首先我们需要做准备工作:

jquery 点击此处

jquery.form.js 点击此处

页面JqueryFormTest.aspx:

rush:js;"> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="JqueryFormTest.aspx.cs" Inherits="JqueryFormTest" %>

img.ashx:

rush:csharp;"> <%@ WebHandler Language="C#" Class="img" %> using System; using System.Web; public class img : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; //获取上传文件的对象 HttpPostedFile img = context.Request.Files["btnfile"]; //获取上传文件名称 string s = img.FileName; //截取获得上传文件名称(ie上传会把绝对路径也连带上,这里只得到文件名称) string str = s.Substring(s.LastIndexOf("\\") + 1); string path = "~/upload/"+ str; //保存文件 img.SaveAs(context.Server.MapPath(path)); //HttpRuntime.AppDomainAppVirtualPath主要是获取应用程序虚拟路径名称,因为响应给页面时不会自动添加而导致无法显示图片 context.Response.Write(HttpRuntime.AppDomainAppVirtualPath + path.Substring(1));//path.Substring(1)用来去除一个~字符 } public bool IsReusable { get { return false; } } }

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《插件用法总结》

希望本文所述对大家jQuery程序设计有所帮助。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...