Skip to content
Browse files

Added debug option

  • Loading branch information...
1 parent 5751551 commit 2beb261180a71d40cb8bbfbaf2733c8ba9651e16 @valums valums committed
Showing with 38 additions and 17 deletions.
  1. +2 −1 client/demo.htm
  2. +21 −4 client/fileuploader.js
  3. +15 −12 readme.md
View
3 client/demo.htm
@@ -25,7 +25,8 @@
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('file-uploader-demo1'),
- action: 'do-nothing.htm'
+ action: 'do-nothing.htm',
+ debug: true
});
}
View
25 client/fileuploader.js
@@ -250,6 +250,8 @@ var qq = qq || {};
*/
qq.FileUploaderBasic = function(o){
this._options = {
+ // set to true to see the server response
+ debug: false,
action: '/server/upload',
params: {},
button: null,
@@ -319,6 +321,7 @@ qq.FileUploaderBasic.prototype = {
}
var handler = new qq[handlerClass]({
+ debug: this._options.debug,
action: this._options.action,
maxConnections: this._options.maxConnections,
onProgress: function(id, fileName, loaded, total){
@@ -851,6 +854,7 @@ qq.UploadButton.prototype = {
*/
qq.UploadHandlerAbstract = function(o){
this._options = {
+ debug: false,
action: '/upload.php',
// maximum number of concurrent uploads
maxConnections: 999,
@@ -865,6 +869,9 @@ qq.UploadHandlerAbstract = function(o){
this._params = [];
};
qq.UploadHandlerAbstract.prototype = {
+ log: function(str){
+ if (this._options.debug && window.console) console.log('[uploader] ' + str);
+ },
/**
* Adds file or file input to the queue
* @returns id
@@ -999,8 +1006,12 @@ qq.extend(qq.UploadHandlerForm.prototype, {
form.appendChild(input);
var self = this;
- this._attachLoadEvent(iframe, function(){
- self._options.onComplete(id, fileName, self._getIframeContentJSON(iframe));
+ this._attachLoadEvent(iframe, function(){
+ self.log('iframe loaded');
+
+ var response = self._getIframeContentJSON(iframe);
+
+ self._options.onComplete(id, fileName, response);
self._dequeue(id);
delete self._inputs[id];
@@ -1045,12 +1056,15 @@ qq.extend(qq.UploadHandlerForm.prototype, {
// iframe.contentWindow.document - for IE<7
var doc = iframe.contentDocument ? iframe.contentDocument: iframe.contentWindow.document,
response;
-
+
+ this.log("converting iframe's innerHTML to JSON");
+ this.log("innerHTML = " + doc.body.innerHTML);
+
try {
response = eval("(" + doc.body.innerHTML + ")");
} catch(err){
response = {};
- }
+ }
return response;
},
@@ -1199,6 +1213,9 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
this._options.onProgress(id, name, size, size);
if (xhr.status == 200){
+ this.log("xhr - server response received");
+ this.log("responseText = " + xhr.responseText);
+
var response;
try {
View
27 readme.md
@@ -79,8 +79,10 @@ If you can't find the one you need, check the readme.txt in the same folder.
sizeLimit: 0, // max size
minSizeLimit: 0, // min size
- // events
-
+ // set to true to output server response to console
+ debug: false,
+
+ // events
// you can return false to abort submit
onSubmit: function(id, fileName){},
onProgress: function(id, fileName, loaded, total){},
@@ -124,24 +126,25 @@ To change params based on the state of your app, use
It can be nicely used in onSubmit callback.
#### Troubleshooting ####
-If you can't get the uploader to work, try the following steps before asking for help.
-Install Chrome or Safari to get their excellent developer tools,
-or alternatively use Firebug. Open resources tab in developer tools.
+If you can't get the uploader to work, please try the following steps
+before asking for help.
+
+If the upload doesn't complete, saying failed.
-Try to upload a file, you will either see an error in the console, or
-a new item will be added to the resource list which should point to your upload
-script.
+* Set the debug option of the FileUploader to true.
+* Open the page where you have a FileUploader.
+* Open developer console in your browser.
+* Try to upload the file. You should see a server serponse.
-Select a content tab, and there you will see a server response. It
-should be {success:true} for completed requests. If it's not, you will
-probably see a reason there.
+It should be {success:true} for completed requests. If it's not,
+then you have a problem with your server-side script.
#### Contributors ####
Thanks to everybody who contributed, either by sending bug reports or donating. And special thanks to:
-John Yeary
+John Yeary
Sidney Maestre
Patrick Pfeiffer
Sean Sandy (SeanJA)

0 comments on commit 2beb261

Please sign in to comment.
Something went wrong with that request. Please try again.