1

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?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

1

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");
 }
}
Kin Chan
  • 29
  • 2