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?

1

1 Answer 1

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");
 }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.