Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/Scripts/jquery.fileDownload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* jQuery File Download Plugin v1.4.2
*
* http://www.johnculviner.com
Expand Down Expand Up @@ -75,7 +75,8 @@ $.extend({
// server's error message with a "helpful" IE built in message
// url - the original url attempted
//
failCallback: function (responseHtml, url) { },
// failReason - the reason provided within the response cookie
failCallback: function (responseHtml, url, failReason) { },

//
// the HTTP method to use. Defaults to "GET".
Expand Down Expand Up @@ -103,6 +104,11 @@ $.extend({
//
cookieValue: "true",

//
//the cookie name to provide a reason if failure
//
cookieNameFailReason: "fileDownloadFailureReason",

//
//the cookie path for above name value pair
//
Expand Down Expand Up @@ -191,7 +197,7 @@ $.extend({
deferred.resolve(url);
},

onFail: function (responseHtml, url) {
onFail: function (responseHtml, url, failReason) {

//remove the perparing message if it was specified
if ($preparingDialog) {
Expand All @@ -203,7 +209,7 @@ $.extend({
$("<div>").html(settings.failMessageHtml).dialog(settings.dialogOptions);
}

settings.failCallback(responseHtml, url);
settings.failCallback(responseHtml, url, failReason);

deferred.reject(responseHtml, url);
}
Expand Down Expand Up @@ -353,7 +359,21 @@ $.extend({
}

if (isFailure) {
internalCallbacks.onFail(formDoc.body.innerHTML, fileUrl);
var failreasonIndex = document.cookie.indexOf(settings.cookieNameFailReason);
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 === settings.cookieNameFailReason) {
failReason = unescape(y);
}
}
}

internalCallbacks.onFail(formDoc.body.innerHTML, fileUrl, failReason);

cleanUp(true);

Expand All @@ -364,7 +384,7 @@ $.extend({
catch (err) {

//500 error less than IE9
internalCallbacks.onFail('', fileUrl);
internalCallbacks.onFail('', fileUrl, '');

cleanUp(true);

Expand Down