Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
106 lines (81 sloc) 2.73 KB
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<div id="uploadFile">
table name: <input type="text" id="fname"><br>
</div>
</body>
</html>
<script>
this.makeUploadForm = function() {
var fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.addEventListener('change', function (e) {
var file = fileInput.files[0];
var textType = /text.*/;
if (file.type.match(textType)) {
var reader = new FileReader();
reader.onload = function (e) {
var Data = reader.result;
var name = document.getElementById("fname").value;
uploadFile(Data,name);
}
reader.readAsText(file);
} else {
alert("File not supported!");
}
});
var f = document.createElement("form");
fileInput.style.display="inline";
f.innerHTML = "upload file:";
f.appendChild(fileInput);
document.getElementById("uploadFile").appendChild(f);
}
this.makeUploadForm();
var uploadFile = function(data,name){
var fileArray = data.split("\n");
headerArray = fileArray[0].split("\t");
dataToSend = '';
counter = 3000;
for(i = 0; i < fileArray.length; i++){
dataToSend += "\n"+ fileArray[i];
counter--;
if(counter == 0){
dataToSend = dataToSend.trim();
dataToSend = "\n"+dataToSend;
$.ajax({
url: "dynamic_loading.php",
type: 'POST',
dataType: "json",
data: {
"header": headerArray,
"upload": dataToSend,
"tableName": name
}
}).success(function (data) {
}).error(function (req, status, error) {
$("body").append(status + ": " + error);
});
dataToSend = '';
counter = 3000;
}
}
dataToSend = dataToSend.trim();
dataToSend = "\n"+dataToSend;
$.ajax({
url: "dynamic_loading.php",
type: 'POST',
dataType: "json",
data: {
"header": headerArray,
"upload": dataToSend,
"tableName": name
}
}).success(function (data) {
}).error(function (req, status, error) {
$("body").append(status + ": " + error);
});
}
</script>
You can’t perform that action at this time.