var formData = new FormData();
formData.append('dataFile', document.getElementById('uploadForm')[0].files[0]);
var file = document.getElementById('uploadForm')[0].files[0];
if (file) {
/* var fileSize = 0;
if (file.size > 1024 * 1024)
fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
else
fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB'; */
var fileNameStr = file.name.split('.');
var len = fileNameStr.length;
var fileType = fileNameStr[len-1];
if(fileType != 'json'){
$('#dataFile').val('');
alert("请上传json文件!");
return;
}
}
var xhr = new XMLHttpRequest();
/* event listners */
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
/* Be sure to change the url below to the url of your upload server side script */
xhr.open("POST", "dataresource/dataFileImport");
xhr.onload = function (event) {
if (xhr.status === 200) {
var rst = $.parseJSON(xhr.response);
if(rst.success){
//code(rst.result);
}else{
alert('无法解析该文件!');
}
}else{
console.log('出错了');
}
};
xhr.send(formData);
formData.append('dataFile', document.getElementById('uploadForm')[0].files[0]);
var file = document.getElementById('uploadForm')[0].files[0];
if (file) {
/* var fileSize = 0;
if (file.size > 1024 * 1024)
fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
else
fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB'; */
var fileNameStr = file.name.split('.');
var len = fileNameStr.length;
var fileType = fileNameStr[len-1];
if(fileType != 'json'){
$('#dataFile').val('');
alert("请上传json文件!");
return;
}
}
var xhr = new XMLHttpRequest();
/* event listners */
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
/* Be sure to change the url below to the url of your upload server side script */
xhr.open("POST", "dataresource/dataFileImport");
xhr.onload = function (event) {
if (xhr.status === 200) {
var rst = $.parseJSON(xhr.response);
if(rst.success){
//code(rst.result);
}else{
alert('无法解析该文件!');
}
}else{
console.log('出错了');
}
};
xhr.send(formData);