简体   繁体   中英

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.

$('.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

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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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