【问题标题】:blueimp jquery file upload error .fileupload is not a functionblueimp jquery 文件上传错误 .fileupload 不是函数
【发布时间】:2017-09-28 23:23:51
【问题描述】:

我正在使用 blueimp jquery 文件上传插件。但有时我会看到一个错误(不是每次刷新)我该如何解决这个问题?

未捕获的类型错误:$(...).fileupload 不是函数 在 HTMLFormElement。 (72:348) 在我 (jquery.min.js:2) 在 Object.fireWith [as resolveWith] (jquery.min.js:2) 在 A (jquery.min.js:4) 在 XMLHttpRequest。 (jquery.min.js:4) (匿名) @ 72:348 i @ jquery.min.js:2 fireWith @ jquery.min.js:2 A @ jquery.min.js:4(匿名)@ jquery.min.js:4

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/blueimp-file-upload/js/vendor/jquery.ui.widget.js"></script>
<script src="bower_components/blueimp-tmpl/js/tmpl.min.js"></script>
<script src="bower_components/blueimp-load-image/js/load-image.all.min.js"></script>
<script src="bower_components/blueimp-canvas-to-blob/js/canvas-to-blob.min.js"></script>
<script src="bower_components/blueimp-file-upload/js/jquery.iframe-transport.js"></script>
<script src="bower_components/blueimp-file-upload/js/jquery.fileupload.js"></script>
<script src="bower_components/blueimp-file-upload/js/jquery.fileupload-ui.js"></script>
<script src="bower_components/blueimp-file-upload/js/jquery.fileupload-process.js"></script>
<script src="bower_components/blueimp-file-upload/js/jquery.fileupload-validate.js"></script>
<script src="bower_components/blueimp-file-upload/js/jquery.fileupload-image.js"></script>

<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<div class="template-upload fade  col-md-2 text-center">
    <div style="max-width:100%; max-height:75px; margin-top:10px">
        <span class="preview"></span>
    </div>

    <div>
        <strong class="error text-danger"></strong>
    </div>

    <div>
        <p class="size">Yükleniyor...</p>
        <div class="progress progress-striped active" role="progressbar"
        aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
        <div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
    </div>

    <div>
        {% if (!i && !o.options.autoUpload) { %}
            <button class="btn btn-primary start" disabled>
                <i class="glyphicon glyphicon-upload"></i>
                <span>Yükle</span>
            </button>
        {% } %}
        {% if (!i) { %}
            <button class="btn btn-warning cancel">
                <i class="glyphicon glyphicon-ban-circle"></i>
                <span>İptal</span>
            </button>
        {% } %}
    </div>
</div>
{% } %}
</script>
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<div class="template-download fade col-md-2 text-center" >
    <div style="max-width:100px; max-height:100px; margin:0 auto;  margin-top:10px">
        <span class="preview">
            {% if (file.thumbnailUrl) { %}
                <a href="{%=file.url%}" title="{%=file.name%}"
                download="{%=file.name%}" data-gallery>
                <img src="{%=file.thumbnailUrl%}" style="max-width:100%; max-height:75px;"></a>
            {% } %}
        </span>
    </div>
    <div>
        {% if (file.error) { %}
            <div><span class="label label-danger">Error</span> {%=file.error%}</div>
        {% } %}
    </div>
    <div>
        <span class="size">{%=o.formatFileSize(file.size)%}</span>
    </div>
    <div class="mt10 text-center">
        {% if (file.deleteUrl) { %}
            <button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                <i class="glyphicon glyphicon-trash"></i>

            </button>
        {% } else { %}
            <button class="btn btn-warning cancel">
                <i class="glyphicon glyphicon-ban-circle"></i>

            </button>
        {% } %}
    </div>
</div>
{% } %}
</script>

<script type="text/javascript">
    $(function () {
        $('#fileupload').fileupload({
            url: 'my.php'
        });
        $('#fileupload').fileupload(
            'option',
            'redirect',
            window.location.href.replace(
                /\/[^\/]*$/,
                '/cors/result.html?%s'
            )
        );
        $('#fileupload').addClass('fileupload-processing');
        $.ajax({
            url: $('#fileupload').fileupload('option', 'url'),
            dataType: 'json',
            context: $('#fileupload')[0]
        }).always(function () {
            $(this).removeClass('fileupload-processing');
        }).done(function (result) {
            $(this).fileupload('option', 'done')
                .call(this, $.Event('done'), {result: result});
        });
    });
</script>

【问题讨论】:

    标签: javascript jquery google-chrome blueimp


    【解决方案1】:

    我修复了额外的 jQuery 代码用户问题。但错误仍然相同。这里有谁想要使用这个解决方案。

    $('#fileupload').bind('fileuploaddone', function (e, data) {
        loadImages(data);
    });
    
    function loadImages(data) {
        $.getJSON('my.php', function (data) {
           var result = tmpl('show-template', data);
              $('#houseImagesDiv').html(result).fadeIn();
           });
    }
    
    loadImages();
    
    $(document).on('click','.delete',function(event){
        event.preventDefault();
        $.getJSON($(this).data('url')).done(function () {
            loadImages();
        });
    });
    

    我在表格上添加了

    <div id="houseImagesDiv"></div>
    

    我做了空的下载js模板。

    <script id="template-download" type="text/x-tmpl">
      // need empty row here 
    </script>
    

    我为新 div 创建新模板。

    <script id="show-template" type="text/x-tmpl">
    {% for (var i=0, file; file=o.files[i]; i++) { %}
        <div class="template-download col-md-2 text-center" >
            <div>
                <span class="preview">
                    <img src="{%=file.thumbnailUrl%}">
                </span>
            </div>
            <div class="mt10 text-center">
                <button class="btn btn-danger delete"
                        data-type="{%=file.deleteType%}"
                        data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %}
                        data-xhr-fields='{"withCredentials":true}'{% } %}>
                    <i class="glyphicon glyphicon-trash"></i>
                </button>
            </div>
        </div>
    {% } %}
    </script>
    

    【讨论】:

      猜你喜欢
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-13
      相关资源
      最近更新 更多