JavaScript why is $(this).data('mycontrol') undefined?

Unfortunately my front end skills are lacking as my role puts me more on the server side / db technologies as opposed to css / js. In any event, I am trying to implement this:

https://github.com/blueimp/jQuery-File-Upload/wiki/Complete-code-example-using-blueimp-jQuery-file-upload-control-in-Asp.Net.

And more specifically I was able to find an asp.net example here:

http://www.webtrendset.com/2011/06/22/complete-code-example-for-using-blueimp-jquery-file-upload-control-in-asp-net/

Basically allowing you to do mass image uploads. I've set up the front end with the correct css and js files. I had to modify some of the js files to make use of on() instead of live() as live is deprecated. My form loads and looks like the following:

enter image description here

So far so good, however, as soon as I "Add file" or drag and drop a file chrome developer tools tells me the following:

Uncaught TypeError: Cannot read property '_adjustMaxNumberOfFiles' of undefined

It specifies the file as jquery.fileupload-ui.js and more specifically points me to this:

var that = $(this).data('fileupload');
that._adjustMaxNumberOfFiles(-data.files.length);

I alerted that and of course it seems to be undefined...But I don't know enough jquery to understand why it is undefined. My fileupload div markup was as follows:

   <div id="fileupload">
                         <form action="/Handler.ashx" method="POST" enctype="multipart/form-data">
                            <div class="fileupload-buttonbar">
                                <label class="fileinput-button">
                                    <span>Add files...</span>
                                    <input id="file" type="file" name="files[]" multiple>
                                </label>
                                <button type="submit" class="start">Start upload</button>
                                <button type="reset" class="cancel">Cancel upload</button>
                                <button type="button" class="delete">Delete files</button>
                            </div>
                           </form>
                            <div class="fileupload-content">
                                <table class="files"></table>
                                <div class="fileupload-progressbar"></div>
                            </div>
                        </div>

So what could be causing this to be undefined? This is what _adjustMaxNumberOfFiles does

  _adjustMaxNumberOfFiles: function (operand) {
            if (typeof this.options.maxNumberOfFiles === 'number') {
                this.options.maxNumberOfFiles += operand;
                if (this.options.maxNumberOfFiles < 1) {
                    this._disableFileInputButton();
                } else {
                    this._enableFileInputButton();
                }
            }
        },

I'm using jquery 2.0.3 and jquery ui 1.10.3

Update

I've gotten it down to the point that the example link which I posted (2nd link above) the only difference is the version of jquery they are using, appears to be 1.8.2 and I am using 2.0.3. The difference and problem is this piece of code:

var that = $(this).data('fileupload');

In the example download this returns some strange object:

a.(anonymous function).(anonymous function) {element: e.fn.e.init[1], options: Object, _sequence: Object, _total: 0, _loaded: 0…}

In my version (using 2.0.3) I am getting undefined for this:

var that = $(this).data('fileupload');

Is there another way I can do this one line of code?

Answer:1

After much playing around in the console window I got it with this:

var that = $("#fileupload").data('blueimpUI-fileupload');

So for anyone that is using anything > jQuery 1.8 please change this line:

var that = $(this).data('fileupload');

to this:

var that = $("#fileupload").data('blueimpUI-fileupload');

Answer:2

I'm running a Django site with XML text stored in TextField properties. It's stored as XML rather than plain text because it's heavily annotated with information about the underlying manuscript, such ...

I'm running a Django site with XML text stored in TextField properties. It's stored as XML rather than plain text because it's heavily annotated with information about the underlying manuscript, such ...

HTML: <script>function dropdown() { console.getElementById("").style.display="block"; }</script> <div id="dropdown"> <ul> <li onclick="dropdown()"><...

HTML: <script>function dropdown() { console.getElementById("").style.display="block"; }</script> <div id="dropdown"> <ul> <li onclick="dropdown()"><...

  1. using onclick event in javascript
  2. onclick with event
  3. using jquery in onclick event

I was using a for loop to conditionally iterate over HTML input and concatenate a pipe separated string. Because I didn't want an ending pipe character I used foo.slice(0, -1). It occurred to me that ...

I was using a for loop to conditionally iterate over HTML input and concatenate a pipe separated string. Because I didn't want an ending pipe character I used foo.slice(0, -1). It occurred to me that ...

  1. javascript empty string falsey
  2. javascript empty string truthy
  3. javascript empty string check
  4. javascript empty string vs null
  5. javascript empty string if null
  6. javascript empty string constant
  7. javascript empty string array
  8. javascript empty string is false
  9. javascript empty string to 0
  10. javascript empty string equals null
  11. javascript empty string regex
  12. javascript empty string to null
  13. javascript empty string is undefined
  14. javascript empty string boolean value
  15. javascript empty string to number
  16. javascript empty string vs undefined
  17. javascript empty string instead of undefined
  18. javascript empty string object key
  19. javascript empty string object
  20. javascript empty string validation

I'm writing some simple code to change the visibility of an image when a button is clicked, but my document.getElementById().value is coming up as undefined. (I've tried replacing .value with .display ...

I'm writing some simple code to change the visibility of an image when a button is clicked, but my document.getElementById().value is coming up as undefined. (I've tried replacing .value with .display ...

  1. getelementbyid not returning value