I am attempting to use the Jquery file upload addon to asynchronously upload files to a C3 http handler. I have gone through the setup steps on the GitHub site for the project. It seems to work fine in Firefox but throws a javascript error in IE ('Exception thrown and not caught'. Line 95, Char 25, File: test.html), even though the file is successfully uploaded. I think my issue is related to the response of my ashx. Can anyone see what I am doing wrong?
Here is the body of the html for my page (test.html):
<form id="file_upload" action="testupload.ashx" method="POST" enctype="multipart/form-data">
<input type="file" name="file" multiple>
<button>Upload</button>
<div>Upload files</div>
</form>
<table id="files"></table>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script src="../Script/jquery.fileupload.js"></script>
<script src="../Script/jquery.fileupload-ui.js"></script>
<script>
/*global $ */
$(function () {
$('#file_upload').fileUploadUI({
uploadTable: $('#files'),
downloadTable: $('#files'),
buildUploadRow: function (files, index) {
return $('<tr><td>' + files[index].name + '<\/td>' +
'<td class="file_upload_progress"><div><\/div><\/td>' +
'<td class="file_upload_cancel">' +
'<button class="ui-state-default ui-corner-all" title="Cancel">' +
'<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
'<\/button><\/td><\/tr>');
},
buildDownloadRow: function (file) {
return $('<tr><td>' + file.name + '<\/td><\/tr>');
}
});
});
</script>
Here is the code in my ashx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
namespace Testing
{
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
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;
}
}
}
}