如何获取文件是否在jQuery中上载

时间:2019-06-18 12:05:44

标签: javascript jquery jsp bootstrap-4

我正在使用Bootstrap上传文件,如果已上传,我想显示关闭按钮(X),否则我不想显示该按钮:

    Dim crParameterFieldDefinitions As 
    ParameterFieldDefinitions
    Dim crParameterFieldDefinition As 
        ParameterFieldDefinition
    Dim crParameterValues As New ParameterValues
    Dim crParameterDiscreteValue As New 
     ParameterDiscreteValue

    crParameterDiscreteValue.Value = TextBox2.Text
    crParameterFieldDefinitions = _
    cryRpt.DataDefinition.ParameterFields
    crParameterFieldDefinition = _
   crParameterFieldDefinitions.Item("cpvid")
    crParameterValues = 
   crParameterFieldDefinition.CurrentValues

    crParameterValues.Clear()
    crParameterValues.Add(crParameterDiscreteValue)
    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

    Form5.CrystalReportViewer1.ReportSource = cryRpt
    Form5.CrystalReportViewer1.Refresh()

    Form5.Show()

我希望X按钮仅在文件上传后才可见。

that X button I want to display only when file upload

1 个答案:

答案 0 :(得分:0)

使用FromData通过AJAX请求发送,并监听成功事件。

const input = document.querySelector('input[type="file"]');

const formData = new FormData();
formData.append('file', input.files[0]);

fetch('https://example.com', {
  method: 'POST',
  body: formData
}).then(() => {
    console.log('File successfully uploaded.');
}).catch(() => {
    console.log('An error occurred while uploading.');
});

注意:您可能必须监听onChange之类的事件来输入文件,并在此事件发生时发送数据。