Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for querystring being incorrectly appended if querystring already exists, and handle null response from server #5

Merged
merged 2 commits into from

2 participants

@1stvamp

If the form action already contains a querystring uploadProgress would append a second question mark followed by the X-Progress-ID, this patch handles this situation correctly and uses an ampersand instead if so.

Also if the server returns with a null or false response, which happens in several situations which use caching intermediaries for signalling upload status when out of the upload process, I've added a patch to just assume this is the end of upload (you can't assume an actual error as there's no other data to go on, an alternative to this might be the pass the XHR object and check for a 50x status header, but I don't need to do this so haven't).

1stvamp added some commits
@1stvamp 1stvamp Check for server response being null if testing locally (processed to…
…o quickly), and correctly append X-Progress-ID with ampersand when there's already a querystring.
12f1e2c
@1stvamp 1stvamp Assume false response from server means we've gone past the upload pr…
…ocess.
7063616
@1stvamp

Bump, /cc @drogus

@drogus
Owner

@1stvamp sorry for delaying it for so long, I think I haven't got the previous notifications due to filters set for github emails - now when github made their notifications system better it came to my main inbox

@drogus drogus merged commit 35b3000 into from
@1stvamp

@drogus no problem! I had the exact same issues with a bunch of pull requests until recently, just decided to go through my pending PR list every month or so to ping people or respond to people asking me for pulls. Cheers :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 17, 2011
  1. @1stvamp

    Check for server response being null if testing locally (processed to…

    1stvamp authored
    …o quickly), and correctly append X-Progress-ID with ampersand when there's already a querystring.
  2. @1stvamp
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 16 deletions.
  1. +23 −16 jquery.uploadProgress.js
View
39 jquery.uploadProgress.js
@@ -75,7 +75,9 @@
var action = $(this).attr("action").replace(old_id[1], uuid);
$(this).attr("action", action);
} else {
- $(this).attr("action", jQuery(this).attr("action") + "?X-Progress-ID=" + uuid);
+ var action = jQuery(this).attr("action");
+ var action_sep = (action.lastIndexOf("?") != -1) ? "&": "?";
+ $(this).attr("action", action + action_sep + "X-Progress-ID=" + uuid);
}
var uploadProgress = $.browser.safari ? progressFrame.jQuery.uploadProgress : jQuery.uploadProgress;
options.timer = window.setInterval(function() { uploadProgress(this, options) }, options.interval);
@@ -89,26 +91,31 @@ jQuery.uploadProgress = function(e, options) {
url: options.progressUrl + "?X-Progress-ID=" + options.uuid,
dataType: options.dataType,
success: function(upload) {
- if (upload.state == 'uploading') {
- upload.percents = Math.floor((upload.received / upload.size)*1000)/10;
+ if (upload) {
+ switch (upload.state) {
+ case 'uploading':
+ upload.percents = Math.floor((upload.received / upload.size)*1000)/10;
- var bar = $.browser.safari ? $(options.progressBar, parent.document) : $(options.progressBar);
- bar.css({width: upload.percents+'%'});
- options.uploading(upload);
- }
+ var bar = $.browser.safari ? $(options.progressBar, parent.document) : $(options.progressBar);
+ bar.css({width: upload.percents+'%'});
+ options.uploading(upload);
+ break;
- if (upload.state == 'done' || upload.state == 'error') {
- window.clearTimeout(options.timer);
- options.complete(upload);
- }
+ case 'done':
+ options.success(upload);
+ case 'error':
+ window.clearTimeout(options.timer);
+ options.complete(upload);
+ break;
+ }
- if (upload.state == 'done') {
+ if (upload.state == 'error') {
+ options.error(upload);
+ }
+ } else {
+ // Null/false/empty response, assume we're out of process
options.success(upload);
}
-
- if (upload.state == 'error') {
- options.error(upload);
- }
}
});
};
Something went wrong with that request. Please try again.