Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在不设置formData的情况下提交其他表单数据_Javascript_Jquery_Jquery File Upload_Chunked Encoding_Multiple File Upload - Fatal编程技术网

Javascript 在不设置formData的情况下提交其他表单数据

Javascript 在不设置formData的情况下提交其他表单数据,javascript,jquery,jquery-file-upload,chunked-encoding,multiple-file-upload,Javascript,Jquery,Jquery File Upload,Chunked Encoding,Multiple File Upload,我正在跟踪并有一个正在提交附加表单数据的工作文件上载,即附加文本区输入字段description[],具有分块和多文件支持,而无需在.fileupload()上设置formData:{}。我的问题是,我只能将字段作为数组提交,description[],并且我无法想出一些逻辑来将适当的description[I]与适当的文件关联起来。我使用的是asp.net mvc,在这种情况下,这不重要 观点: <script type="text/javascript"> $(docum

我正在跟踪并有一个正在提交附加表单数据的工作文件上载,即附加文本区输入字段
description[]
,具有分块和多文件支持,而无需在
.fileupload()上设置
formData:{}
。我的问题是,我只能将字段作为数组提交,
description[]
,并且我无法想出一些逻辑来将适当的
description[I]
与适当的文件关联起来。我使用的是asp.net mvc,在这种情况下,这不重要

观点:

<script type="text/javascript">
    $(document).ready(function () {
        $('#btnContinue').prop('disabled', true);
        $('#fileupload').fileupload({
            url: '@Url.Action("UploadChunk", "Upload")',
            maxChunkSize: 1048576,
        }).addClass('fileupload-processing')
        .bind('fileuploadalways', function (e, data) {
            if ($('#fileIds').val().indexOf(';' + data.result.id + ';') == -1) {
                var pre = $('#fileIds').val() == "" ?  ';' : '';
                var append = $('#fileIds').val() + pre + data.result.id + ';';
                $('#fileIds').val(append);
            }
        })
        .bind('fileuploaddone', function (e, data) {
            $('#btnContinue').prop('disabled', false);
        });

        $.ajax({
            url: $('#fileupload').fileupload('option', 'url'),
            dataType: 'json',
            context: $('#fileupload')[0]
        }).always(function () {
            $(this).removeClass('fileupload-processing');
        });
    });
</script>
@using (Html.BeginForm("FileSet", "Upload", FormMethod.Post, new { id = "fileupload" } ))
{
    @Html.AntiForgeryToken()
    @Html.Hidden("fileIds", "", new { @id = "fileIds" })

    <div class="form-horizontal">
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <div class="row fileupload-buttonbar">
            <div class="col-lg-7">
                <!-- The fileinput-button span is used to style the file input field as button -->
                <span class="btn btn-success fileinput-button">
                    <i class="glyphicon glyphicon-plus"></i>
                    <span>Add files...</span>
                    <input type="file" name="files[]" multiple>
                </span>
                <button type="submit" class="btn btn-primary start" id="btnStartUpload">
                    <i class="glyphicon glyphicon-upload"></i>
                    <span>Start upload</span>
                </button>
                <button type="reset" class="btn btn-warning cancel" id="btnCancelUpload">
                    <i class="glyphicon glyphicon-ban-circle"></i>
                    <span>Cancel upload</span>
                </button>
                <button type="button" class="btn btn-danger delete" id="btnDeleteUpload">
                    <i class="glyphicon glyphicon-trash"></i>
                    <span>Delete</span>
                </button>
                <input style="visibility: hidden" type="checkbox" class="toggle">
                <!-- The global file processing state -->
                <span class="fileupload-process"></span>
            </div>
            <!-- The global progress state -->
            <div class="col-lg-5 fileupload-progress fade">
                <!-- The global progress bar -->
                <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                    <div class="progress-bar progress-bar-success" style="width:0%;"></div>
                </div>
                <!-- The extended global progress state -->
                <div class="progress-extended">&nbsp;</div>
            </div>
        </div>
        <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>     

        <div class="row">
            <div class="col-md-10">
                <button type="submit" id="btnContinue" class="btn btn-primary">Continue</button>
            </div>
        </div>
    </div>
}

<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
    <td>
        <span class="preview"></span>
    </td>
    <td>
        <p class="name">{%=file.name%}</p>
        <strong class="error text-danger"></strong>
    </td>
    <td>
        <input type="hidden" name="locator[]" value="{%=file.name%}" />
        <textarea name="description[]" placeholder="Enter description" class="form-control" rows="3"></textarea>
        <strong class="error text-danger"></strong>
    </td>
    <td>
        <p class="size">Processing...</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>
    </td>
    <td>
        {% if (!i && !o.options.autoUpload) { %}
        <button class="btn btn-primary start" disabled>
            <i class="glyphicon glyphicon-upload"></i>
            <span>Start</span>
        </button>
        {% } %}
        {% if (!i) { %}
        <button class="btn btn-warning cancel">
            <i class="glyphicon glyphicon-ban-circle"></i>
            <span>Cancel</span>
        </button>
        {% } %}
    </td>
</tr>
{% } %}
</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++) { %}
<tr class="template-download fade">
    <td>
        <span class="preview">
            {% if (file.thumbnailUrl) { %}
            <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
            {% } %}
        </span>
    </td>
    <td>
        <p class="name">
            {% if (file.url) { %}
            <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
            {% } else { %}
            <span>{%=file.name%}</span>
            {% } %}
        </p>
        {% if (file.error) { %}
        <div><span class="label label-danger">Error</span> {%=file.error%}</div>
        {% } %}
    </td>
    <td>
        <span class="size">{%=o.formatFileSize(file.size)%}</span>
    </td>
    <td>
        {% 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>
            <span>Delete</span>
        </button>
        <input type="checkbox" name="delete" value="1" class="toggle">
        {% } else { %}
        <button class="btn btn-warning cancel">
            <i class="glyphicon glyphicon-ban-circle"></i>
            <span>Cancel</span>
        </button>
        {% } %}
    </td>
</tr>
{% } %}

$(文档).ready(函数(){
$('btnContinue').prop('disabled',true);
$('#fileupload')。fileupload({
url:'@url.Action(“UploadChunk”,“Upload”),
maxChunkSize:1048576,
}).addClass('fileupload-processing')
.bind('fileuploadalways',函数(e,数据){
if($('#fileIds').val().indexOf(';'+data.result.id+';'))=-1){
var pre=$(“#fileid”).val()==”?”;“:”;
var append=$('#fileIds').val()+pre+data.result.id+';';
$('#fileid').val(追加);
}
})
.bind('fileuploaddone',函数(e,数据){
$('btnContinue').prop('disabled',false);
});
$.ajax({
url:$('#fileupload')。fileupload('option','url'),
数据类型:“json”,
上下文:$('#fileupload')[0]
}).always(函数(){
$(this.removeClass('fileupload-processing');
});
});
@使用(Html.BeginForm(“FileSet”,“Upload”,FormMethod.Post,new{id=“fileupload”}))
{
@Html.AntiForgeryToken()
@Html.Hidden(“fileIds”,“”,new{@id=“fileIds”})

@Html.ValidationSummary(true,“,new{@class=“text danger”}) 添加文件。。。 开始上传 取消上传 删除 继续 } {%for(var i=0,file;file=o.files[i];i++){%}

{%=file.name%}

处理

{%if(!i&&!o.options.autoUpload){%} 开始 {% } %} {%if(!i){%} 取消 {% } %} {% } %} {%for(var i=0,file;file=o.files[i];i++){%} {%if(file.thumbnailUrl){%} {% } %}

{%if(file.url){%} {%}其他{%} {%=文件名%} {% } %}

{%if(file.error){%} 错误{%=file.Error%} {% } %} {%=o.formatFileSize(file.size)%} {%if(file.deleteUrl){%} 删除 {%}其他{%} 取消 {% } %} {% } %}

控制员:

[HttpPost]
public ContentResult UploadChunk(string[] description)
{
    ParseRequestHeaderRanges(this.Request);
    var r = new List<UploadFilesResult>();
    var i = 0;

    foreach (string file in Request.Files)
    {
        HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
        if (hpf.ContentLength == 0)
            continue;

        var uploader = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
        var result = DataTranslator.UploadChunk(hpf.InputStream, hpf.FileName, description[i], hpf.ContentType,
            hpf.ContentLength, (int)hpf.InputStream.Length, this.TotalBytes, uploader);
        r.Add(result);
        i++;
    }

    return Content("{\"id\":\"" + r[0].Id + "\",\"name\":\"" + r[0].Name + "\",\"type\":\"" + r[0].Type + "\",\"size\":\"" + string.Format("{0} bytes", r[0].Length) + "\"}", "application/json");
}
var result = DataTranslator.UploadChunk(
  hpf.InputStream, 
  hpf.FileName, 
  description[hpf.FileName],
  hpf.ContentType, 
  hpf.ContentLength, 
  (int)hpf.InputStream.Length, 
  this.TotalBytes, 
  uploader
);
[HttpPost]
public ContentResult UploadChunk(字符串[]说明)
{
ParseRequestHeaderRanges(this.Request);
var r=新列表();
var i=0;
foreach(Request.Files中的字符串文件)
{
HttpPostedFileBase hpf=Request.Files[file]作为HttpPostedFileBase;
如果(hpf.ContentLength==0)
继续;
var uploader=System.Security.Principal.WindowsIdentity.GetCurrent().Name;
var result=DataTranslator.UploadChunk(hpf.InputStream,hpf.FileName,description[i],hpf.ContentType,
hpf.ContentLength,(int)hpf.InputStream.Length,this.TotalBytes,uploader);
r、 添加(结果);
i++;
}
返回内容(“{”id\“:\”+r[0]。id+“\”,““name\”:\”+r[0]。name+“\”,“type\”:\”+r[0]。type+“\”,“size\”:\”+string.Format(“{0}字节”,r[0]。Length)+“\”,“application/json”);
}

与其让它成为数组,不如让它成为散列?比如说使用文件名?这样你就不必依赖于事情的正确顺序

<textarea name="description[{%=file.name%}]" placeholder="Enter description" class="form-control" rows="3"></textarea>

不幸的是,这不起作用。控制器方法的字符串[]描述参数现在为空。我假设description[]到description[file.name]的连接没有正确发生。有什么进一步的建议吗?你能展示一下你日志中的参数是什么样的吗?也许您需要将描述初始化为散列而不是数组。我不熟悉您的服务器端jazz。