jQuery UI Widget Factory - Upload Progress Trigger Test

HTML

<script src="https://raw.github.com/jquery/jquery-ui/1.8.17/ui/jquery.ui.widget.js"></script>
<div id="test"></div>

JavaScript

$.widget('test.trigger', {
    options: {
        progress: function (e) {
            $('<p/>')
                .text(e.loaded)
                .appendTo(this);
        }
    },
    _create: function () {
        var widget = this;
        $.ajax({
            data: {test: (new Array(99999)).join('test')},
            type: 'POST',
            url: '/echo/html/',
            xhr: function () {
                var xhr = $.ajaxSettings.xhr();
                xhr.upload.addEventListener('progress', function (e) {
                    try {
                        widget._trigger('progress', e);
                    } catch (ex) {
                        $('<p/>')
                            .text(ex.toString())
                            .appendTo(widget.element);
                    }
                }, false);
                return xhr;
            }
        });
    }
});
$('#test').trigger();