Because naming a variable as formData doesn't make it a formdata object. Does the following make a new integer value?
var integer = 'Afzaal Ahmad Zeeshan';
No. You're doing the same, what you need is to use
FormData
object; not a plain JavaScript object. I wrote an article that covers this topic, kindly read it,
Uploading the Files – HTML5 and jQuery Way![
^]
What you need is an HTML form, then you can create a new
FormData
object from it and upload it to server, sample,
<form method="post" id="formid">
<!--
</form>
Then the JavaScript would be,
var formData = new FormData($('#formid')[0]);
$.ajax({
url: 'path',
data: formData,
success: function(response) {
}
});
Read the article for more deeper overview of this.
FormData - Web APIs | MDN[
^]