提交到ashx时,Jquery文件上传错误

我试图使用Jquery文件上传插件异步上传文件到C3 http处理程序。 我已经完成了项目的GitHub站点上的设置步骤。 它似乎在Firefox中正常工作,但在IE中抛出了一个javascript错误(’exception抛出并未捕获’。第95行,字符25,文件:test.html),即使文件已成功上传。 我认为我的问题与我的ashx的反应有关。 谁能看到我做错了什么?

这是我的页面的html主体(test.html):

Upload files
/*global $ */ $(function () { $('#file_upload').fileUploadUI({ uploadTable: $('#files'), downloadTable: $('#files'), buildUploadRow: function (files, index) { return $('' + files[index].name + '' + '
' + '' + '

这是我的ashx中的代码:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO; namespace Testing { ///  /// Summary description for $codebehindclassname$ ///  public class TestUpload : IHttpHandler { public void ProcessRequest(HttpContext context) { HttpPostedFile fileupload = context.Request.Files[0]; string strFileName = Path.GetFileName(fileupload.FileName); string strExtension = Path.GetExtension(fileupload.FileName).ToLower(); string strSaveLocation = context.Server.MapPath("Upload") + "\\" + strFileName; fileupload.SaveAs(strSaveLocation); context.Response.ContentType = "text/plain"; context.Response.Write("{\"name\":\"" + fileupload.FileName + "\",\"type\":\"" + fileupload.ContentType + "\",\"size\":\"" + fileupload.ContentLength + "\"}"); } public bool IsReusable { get { return true; } } } } 

尝试改变:

 context.Response.Write("{\"name\":\"" + fileupload.FileName + "\",\"type\":\"" + fileupload.ContentType + "\",\"size\":\"" + fileupload.ContentLength + "\"}"); 

对此:

 context.Response.Write("{\"name\":\"" + fileupload.FileName + "\", type:\"" + fileupload.ContentType + "\",size:\"" + fileupload.ContentLength + "\"}"); 

你传回来的对象只是格格不入。 这应该够了吧。

我能够让这个工作……

首先,我尝试使用硬编码值来获取名称,类型和大小响应,并发现它有效。 这是我用过的:

 context.Response.Write("{\"name\":\"test\",\"type\":\"test\",\"size\":\"12345\"}"); 

然后我注意到fileupload.FileName给出了文件的完整路径并假设这是问题所在。 当我在response.write行中将fileupload.FileName更改为strFileName时,它在Firefox和IE中都能成功运行。 这是一条有用的线:

 context.Response.Write("{\"name\":\"" + strFileName + "\",\"type\":\"" + fileupload.ContentType + "\",\"size\":\"" + fileupload.ContentLength + "\"}");