简体   繁体   English

如何警告有关文件上传(使用Ajax)完成的消息?

[英]How to alert message about file upload(using ajax) completition?

I use following form to file upload: 我使用以下形式上传文件:

<form method="POST"  action="uploadImage" enctype="multipart/form-data" id="imageUploadForm">
               <input type="file" class="file" name="file"/>
</form>

and following ajax to send content to server. 然后跟随ajax将内容发送到服务器。

$('.file').click(function(){
    var formData = new FormData($('#imageUploadForm')[0]);
    $.ajax({
        url: 'uploadImage',  //Server script to process data
        type: 'POST',
        success: alertSucces,
        data: formData,
        cache: false,
        contentType: false,
        processData: false
    });
});

function alertSucces(){
    alert("success");
}

I see alert "success" as soon as I clicked on button. 单击按钮后,我立即看到警报“成功”。 Expected result - see this message as soon as file will load on server. 预期的结果-将文件加载到服务器上后立即查看此消息。

What do I wrong? 我怎么了

You should read about ajax document from here first 您应该先从这里阅读有关ajax文档的信息

After the upload is finished it should have a return message like "upload complete" and this message should be handled in your ajax function like : 上传完成后,它应该有一个返回消息,例如“ upup complete”,并且应该在您的ajax函数中处理该消息,例如:

success : function(data){
 if(data == "upload complete"){
  alert("success");
 }
}

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

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