转载:http://www.cnblogs.com/Irving/archive/2013/03/01/2939292.html

下载:http://www.phpletter.com/download_project_version.php

就是利用Iframe ,使用什么没有好说的

HTML


<script src="AjaxFileUploaderV2.1/jquery.js" type="text/javascript"></script>
<script src="AjaxFileUploaderV2.1/ajaxfileupload.js" type="text/javascript"></script>
<script type="text/javascript">
function ajaxFileUpload() {
$("#loading").ajaxStart(function () {
$(this).show();
}).ajaxComplete(function () {
$(this).hide();
});

$.ajaxFileUpload({
url: 'Handler1.ashx',
secureuri: false,
fileElementId: 'file',
dataType: 'json',
data: { name: 'Irving', id: '1991428' },
success: function (data, status) {
alert(data.msg);
},
error: function (data, status,e) {
alert(e);
}
}
)
return false;
}
</script>
</head>
<body>
<img >
Upload</button>
</form>
</body>

hander测试下


context.Response.ContentType = "text/html";
HttpPostedFile file = context.Request.Files["fileToUpload"];
if (file != null && string.IsNullOrEmpty(file.FileName) == false)
{
file.SaveAs(context.Server.MapPath("~/Files/") + file.FileName);
}
context.Response.Write("{status:'200',success:true,msg:'" + "OK" + "'}");

注意问题

1.返回JSON格式(http://bbs.csdn.net/topics/390050342),context.Response.ContentType = "text/html"; ,否则浏览器总是提示将返回的JSON结果另存为文件

2.jQuery.handleError(s, xml, status, e); jquery的handleError函数,但此函数在1.4.2之后不存在了,所以要不修改插件源码,或者用低版本了啦

3.IE9兼容性问题 找不到链接了

4.ajaxToolkit http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx


5.struts2 http://www.blogjava.net/sxyx2008/archive/2010/11/02/336826.html

相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2021-09-01
  • 2021-06-04
  • 2021-12-27
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-14
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2022-02-23
  • 2022-12-23
相关资源
相似解决方案