I have the following code for, uploading the file using ajax because I don't want to use form action . But I unable to do so. The code is :
Select xml file to upload:
<input type="file" name="fileToUpload" id="uploadFile">
<input type="submit" id="upload_xml" value="Upload Xml">
The ajax code is:
$('#upload_xml').on('click', function() {
var file_data = $('#uploadFile').prop('files')[0];      
var form_data = new FormData();
console.log('hi'+file_data); // this gives [object File]
form_data.append('file', file_data);
console.log('yoyo'+form_data);  // this gives  [object FormData]              
$.ajax({
    url: 'upload.php',
    dataType: 'text',  
    cache: false,
    contentType: false,
    processData: false,
    data: form_data,                         
    type: 'post',
    success: function(response){
        alert(response); 
    }
 });
});
I saw many discussions on various threads, but none work for me. I have done this before without any error, I don't know what is the error :( where I am wrong here. Is there any js file that I need to include??