I got an idea how to pass failure messages from server to client, please comment if this is a possible feature for fileDownload!
In serverside, when my download handler fails, I write a cookie with a failure message like so (ASP.net C#)
Response.SetCookie(new System.Web.HttpCookie("failureReason", Messages.FileNotFound) { Path = "/" });
Then in fileDownload.js checkFileComplete() I added a check to see if failureReason was set
var failreasonIndex = document.cookie.indexOf("failureReason");
var failReason = undefined;
if (failreasonIndex != -1) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x === "failureReason") {
failReason = unescape(y);
}
}
}
And then everywhere I found I added the failreason variable; for example
internalCallbacks.onFail(formDoc.body.innerHTML, fileUrl, failReason);
settings.failCallback(responseHtml, url, failReason);
Then in the usage side I did the following and it worked just fine!
$.fileDownload('/Print', {
successCallback: function (url) {
//...
},
failCallback: function (responseHtml, url) {
debug(responseHtml);
///...
I got the debug message at least in IE9 64bit. Is it possible to implement this in the filedownload core? This way of passing messages seems to work quite well, did I miss something? Would this kind of approach work generally for fileDownload? Any caveats or browser support issues I didn't catch?
The only issue so far is that the cookie data for some reason was not unicode, so I couldn't get "ä,ö" working but I suspect that's just some newbie error from me.