读书人

jquery 一步请求上传图片【高分求解】

发布时间: 2012-04-18 15:01:59 作者: rapoo

jquery 一步请求上传图片【高分求解】
功能:如题 通过ajax请求上传图片

$.ajax({
url: "Handler/Handler.ashx",
data: { method: "ImageFile", 这里的参数该怎么写 },
dataType: "json",
timeout: 10000,
async: false,
success: function(data) {

alert(data);
}
})
Handler.ashx处理页面我该怎么接收
高手们,抽出几分钟的时间帮我写一下,

[解决办法]
jquery.ajaxfileupload.js
[解决办法]

探讨

引用:
jquery.ajaxfileupload.js

可以写个事例代码么?或者帮我找个有事例代码的网站也行

[解决办法]


http://www.cnblogs.com/zhongweiv/archive/2011/11/29/CutAvatar.html
[解决办法]
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script src="jquery-1.7.1.min.js"></script>
<script src="jquery.form.js"></script>
<script type="text/javascript">
function upload() {
$("#form1").ajaxSubmit({
success: function (str) {
alert(str);
},
error: function (error) { alert(error); },
url: 'handler1.ashx', /*设置post提交到的页面*/
type: "post", /*设置表单以post方法提交*/
dataType: "text" /*设置返回值类型为文本*/
});
}
</script>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<input type="file" id="file" name="file" />
<asp:Button ID="Button1" runat="server" Text="上传" OnClientClick="upload();return false;" />
</form>
</body>

handler1.ashx

<%@ WebHandler Language="C#" Class="handler1" %>

using System;
using System.Web;

public class handler1 : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
HttpPostedFile file = context.Request.Files[0];
String fileName = System.IO.Path.GetFileName(file.FileName);
file.SaveAs(context.Server.MapPath("~/") + fileName);
context.Response.Write("OK");
}

public bool IsReusable {
get {
return false;
}
}

}





http://malsup.github.com/jquery.form.js

读书人网 >asp.net

热点推荐