LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

Uncaught TypeError: this.addButton is not a function #202

Closed JasperTey closed 6 years ago

JasperTey commented 6 years ago

Right off the bat, I'm getting the following error when attempting to use the plugin:

Uncaught TypeError: this.addButton is not a function

Triggered on line 718:

this.addButton( this._opts.button );

My instantiation code (edited slightly for brevity):

var uploader = ss.SimpleUpload({
    button: $('#upload-button'),
    url: 'path/to/handler',
    name: 'uploadfile',
    responseType: 'json'
});

What am I missing here? I'm using RequireJS, if that makes any difference.

JasperTey commented 6 years ago

Adding the following line after Line 703 appears to have resolved it:

    ss.extendObj( this, ss.SimpleUpload.prototype ); // <--- ADDED LINE
    ss.extendObj( this._opts, ss._options ); // Include any setup options
    ss.extendObj( this._opts, options ); // Then add options for this instance

This is a rather ad-hoc fix, of course. Could anyone advise if this is a proper solution? It seems like nobody else is experiencing this issue to begin with.

JasperTey commented 6 years ago

I realized what my mistake was. I wasn't instantiating using the new keyword.

// Works
var uploader = new ss.SimpleUpload(options);

// Does not work
var uploader = ss.SimpleUpload(options);

Case closed!