简体   繁体   English

JQuery:文件上传不是 function

[英]JQuery: fileupload is not a function

Good day everyone.今天是个好日子。 I have the following problem:我有以下问题:

I need to check if the form with input (type is file) is ready to submit (file upload must be completed).我需要检查带有输入(类型为文件)的表单是否准备好提交(必须完成文件上传)。 I tried to check if the file is uploaded by JQuery function: fileupload('active') , but I received this error: Uncaught TypeError: fileInput.fileupload is not a function .我试图检查文件是否是由 JQuery function: fileupload('active')上传的,但我收到了这个错误: Uncaught TypeError: fileInput.fileupload is not a function

The code is here:代码在这里:

for (let i = 0; i < fileForms.length; i++) {
    var subFormInput = document.createElement("input");
    subFormInput.setAttribute("type", "hidden");
    subFormInput.setAttribute("name", "submittedFormId");
    subFormInput.setAttribute("value", response.submittedFormId);
    fileForms[i].appendChild(subFormInput);
    i=0;
    fileInput = fileForms[i].querySelector('input[name="answer"]');
    console.log(fileInput);
    while (fileInput.fileupload('active') > 0) {
        i++;
    }
    fileForms[i].submit();
}

I solved problem by using FileReader.我通过使用 FileReader 解决了问题。

for (let i = 0; i < fileForms.length; i++) {
    var subFormInput = document.createElement("input");
    subFormInput.setAttribute("type", "hidden");
    subFormInput.setAttribute("name", "submittedFormId");
    subFormInput.setAttribute("value", response.submittedFormId);
    fileForms[i].appendChild(subFormInput);
    fileInput = fileForms[i].querySelector('input[name="answer"]');
    if (fileInput.value != "") {
        const reader = new FileReader();
        const file = fileInput.files[0];
        reader.readAsArrayBuffer(file);
        reader.onload = function () {
            fileForms[i].submit();
            console.log("file is ready");
        };
    } else {
        fileForms[i].submit();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM