Blueimp jQuery文件上传 - 无法更改输入名称

时间:2017-01-26 14:32:39

标签: jquery file upload blueimp

我尝试使用BlueImp jQuery File Uploader(https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin)。它运行良好,但只能使用输入字段的orinial name属性“files []”。 当我使用其他名称时,JSON响应为空:

{ “文件”:[]}

这是我的代码:

<tr>
    <td>
        <label>Photos</label>
    </td><td id="photos_container">
        <div class="progress">
            <div class="bar" style="width: 0%;"></div>
        </div>
        <span class="btn btn-success fileinput-button">
            <i class="glyphicon glyphicon-plus"></i>
            <span>Select files...</span>
            <input id="photos" type="file" name="photos[]" multiple>
        </span>
    </td>
</tr>

<script>
    jQuery(document).ready(function($){
        $(function () {
            $('#photos_container').fileupload({
                url: 'tmp/',
                dataType: 'json',
                fileInput: $('#photos'),
                paramName: 'photos[]',
                progressall: function (e, data) {
                    var progress = parseInt(data.loaded / data.total * 100, 10);
                    $('#photos_container .progress .bar').css(
                        'width',
                        progress + '%'
                    );
                },
                done: function (e, data) {
                    $.each(data.result.files, function (index, file) {
                        $('<p/>').text(file.name).appendTo('#photos_container');
                    });
                }
            });
        });
    });
</script>

我再说一遍,但代码的输入按钮“files []”的默认名称效果很好,所以问题不是路径问题。

编辑:我尝试使用和不使用fileInput和paramName选项,但我没有工作

1 个答案:

答案 0 :(得分:0)

name属性用于引用JavaScript中的元素,或在提交表单后引用表单数据。

您的文件数据将存放在photos属性中。

相关问题