I have an ajax image upload on my site which isn't working in IE. The first problem I noticed is that the "FormData" type was undefined in IE. I came across the workaround I'm using in the ajax call below. However, the ajax call is only returning the error function when clicking upload, never hitting my controller action "UpdateAvatar". Works perfect in every other browser. Does anyone have any experience with this?
<div class="modal-body">
<input type="file" name="UploadFile" id="uploadfile">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
<button type="button" id="updateAvatarBtn" class="btn-success btn">Upload</button>
</div>
$('#updateAvatarBtn').click(function (event) {
var file = $('#uploadfile').get(0).files;
if (typeof FormData == "undefined") {
var data = [];
data.push('data', JSON.stringify(file));
}
else {
var data = new FormData();
data.append("file", file[0]);
}
$.ajax({
url: 'AccountSetup/updateAvatar',
type: 'POST',
contentType: false,
processData: false,
data: data,
success: function (response) {
$('#imgPreview').attr("src", response);
$('#uploadImageModal').modal('hide');
toastr.success('Image Upload Successful');
},
error: function () {
toastr.error('Image Upload Unsuccessful. Please try again.');
}
})
})