Every time I try to retrieve a file larger than 0.5MB from the SQL database using AJAX, an error occurs. What am I doing wrong here?
$(document).ready(function () {
loadFileData();
});
function loadFileData() {
$.ajax({
type: "GET",
url: "/File/FileIndex",
dataType: "JSON",
success: function (data) {
$.each(data, function (i, val) {
var trow = $('<tr/>').data("id", val.id);
var trowa = $('<tr/>');
var trowb = $('<tr/>').data("id", val.id);
trow.append('<td colspan="2"><a href="#" class="FileDownload">' + escape(val.Name) +'</a></td>');
trowa.append('<td><input type="file" id="FileUpload" /></form></td>');
trowb.append('<td><input type="button" class="btnUpload" value="Upload File" /><input type="button" id="btnClear" value="Clear" /></td>');
tab.append(trow);
tab.append(trowa);
tab.append(trowb);
});
$("#showFiles").html(tab);
},
error: function (error) {
alert("Failed! Please try again." + error);
}
});
var tab = $('<table style="width:100px" border=1 class=MyTable></table>');
}
This is my controller:
//GET: File
public JsonResult FileIndex()
{
List<tblFile> fileList = new List<tblFile>();
using (FileDBEntities db = new FileDBEntities())
{
fileList = db.tblFiles.ToList();
}
return new JsonResult { Data = fileList, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
It works perfectly with small files, but why does it fail when trying to retrieve a file larger than 0.5MB? The error message I am receiving is:
function(){if(a){var t=a.length;(function r(t){v.each(t,function(t,n){var i=v.type(n);i==="function"?
(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this}