meenakshi luthra

meenakshi luthra

  • NA
  • 48
  • 4.5k

issue in Ajax call while uploading excel file

Apr 18 2018 12:43 AM
Hi,
 
I have following Jquery in mvc core view:
 
$(document).ready(function () {
$("#btnUploadSave").click(function () {
var fileUpload = $("#files").get(0);
var files = fileUpload.files;
var data = new FormData();
for (var i = 0; i < files.length; i++) {
data.append(files[i].name, files[i]);
}
$.ajax({
type: "POST",
url: "/Creator/SaveBatchMenbersFromExcel",
contentType: false,
processData: false,
datatype : json,
data: data,
headers: { __RequestVerificationToken: $("input[name=__RequestVerificationToken]").val() },
success: function (message) {
alert(message);
$("#txtExcelFile").val('');
$("#txtExcelFile").attr("placeholder", "Drop a file here!");
$('#ddlBatchCsv').prop('selectedIndex', 0);
},
error: function () {
alert("There was error uploading files!");
}
});
});
 
and below is the html of input
 
<input type="file" id="files" name="filesToUpload[]" style="display:none;" class="file">
 
while saving data of excel file I am always getting alert of error function. Please help me where is the mistake?? 

Answers (13)