================Edit=====================================================
Hello! Thanks so much for everyone who answered and tried to help me. I was able to get what I needed by using iframe as suggested by @Kaiido since my previous code doesn't work in ie8. Thanks to this as well: JQuery file posting using iframe Again. Thanks so much!
=======================================================================
I have an upload form. I am able to upload the file on submission. The problem is I am trying to add/append a delete button once the user chooses a file to upload.
I need it to look like this:
Goals:
1. When user clicks on Delete button, the filelist should go back to empty.
2. Changing the file should behave like clicking on the Delete button.
3. It needs to work in IE 8. It sucks.
Input Form:
Attachment: <input type="file" name="upload" id="upload">
<a href="#" id="btnSubmit">Submit</a>
JS:
var files;
$('input[type=file]').on('change', prepareUpload);
function prepareUpload(event)
{
files = event.target.files; // I'm not sure but the problem might be on this part. Maybe I could get the opposite of this or negate this?
}
function uploadFiles(event)
{
event.stopPropagation();
event.preventDefault();
var data = new FormData();
$.each(files, function(key, value)
{
data.append(key, value);
});
$.ajax({
url: 'execs/upload.php?files',
type: 'POST',
data: data,
cache: false,
dataType: 'json',
processData: false,
contentType: false,
success: function(data)
{
console.log('Uploaded');
},
error: function()
{
console.log('Failed');
}
})
}
$("#btnSubmit").click(function(e)
{
uploadFiles(event);
})
Thank you so much for your help!