Google Chrome's console is telling me

Uncaught TypeError: Illegal Invocation

when the following function is invoked

   $('#txtUploadFile').on('change', function (e) {
        var files = e.target.files;
        if (files.length > 0) {
            if (window.FormData !== undefined) {
                var data = new FormData();
                for (var x = 0; x < files.length; x++) {
                    data.append("file" + x, files[x]);
                }

                $.ajax({
                    xhr: function() {
                        var xhr = new window.XMLHttpRequest();
                        xhr.upload.addEventListener("progress", function(evt) {
                            if (evt.lengthComputable) {
                                var percentComplete = evt.loaded / evt.total * 100;
                                console.log("percentComplete = " + percentComplete);
                            }
                            else
                            {
                                console.log("lengthComputable evaluated to false;")
                            }
                        }, false);

                        xhr.addEventListener("progress", function(evt) {
                            if (evt.lengthComputable) {
                                var percentComplete = evt.loaded / evt.total * 100;
                                console.log("percentComplete = " + percentComplete);
                            }
                            else
                            {
                                console.log("lengthComputable evaluated to false;")
                            }
                        }, false);

                        return xhr;
                    },
                    type: 'POST',
                    url: '@Url.Action("upload","FileUploadAsync")',
                    data: data,
                    success: function(data){
                        console.log("success!");
                    }
                });
            } else {
                alert("This browser doesn't support HTML5 file uploads!");
            }
        }
    });

I've looked through StackOverflow posts on this issue and none of the causes relate to anything I can see in mine. I'm not sure if it matters, but I can post the HTML and the controller if that could be part of the problem.

Related posts

Recent Viewed