Skip to content
Permalink
c8a8193260
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
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>