I'm trying to display the upload.txt records into a html table.
The upload.txt file is located at this url : http://localhost:3000/upload. When we call this url it will get upload.txt file.
Actually I'm using node.js here.So I'm routing here like this :
app.get('/upload', function(req, res) {
res.sendfile('views/upload.txt');
});
My upload.txt :
client_ip
1.0.230.145
1.1.145.219
1.1.214.239
1.11.112.100
1.112.218.165
1.112.98.44
1.113.55.77
1.114.193.160
1.115.77.221
1.115.81.190
1.124.150.22
1.124.158.81
My table.html:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color:#FFBD0C;
}
table {
border-collapse:separate;
border-spacing:1px;
background:#CCC;
margin-right:200px
}
table th {
background:#EEE;
font-weight:600;
padding:10px 20px;
text-align:center;
}
table tbody {
padding:0; margin:0;
border-collapse:collapse;
border-spacing:0px;
}
table td {
background:#C7DBED;
padding:5px 10px;
text-align:center;
}
</style>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'></script>
<script>
var userListData = [];
$(document).ready(function() {
populateTable();
});
function populateTable() {
var tableContent = '';
$.get( 'http://localhost:3000/upload', function( data ) {
alert(data); // Here I'm able to get the entire text file data.
$.each(data, function(){
alert(data); // here I'm unable to get the data.
tableContent += '<tr>';
tableContent += '<td>' + this.client_ip + '</td>';
tableContent += '</tr>';
});
$('#tablediv').html(tableContent);
});
};
</script>
</head>
<body>
<h2 style="color:brown; margin-left:490px;margin-top:150px;">Upload Clients</h2>
<table width="60%" id="tab" style="margin-left:200px;">
<thead>
<tr>
<th>Clients</th>
</tr>
<thead>
<tbody id="tablediv">
</tbody>
</table>
</body>
</html>
At this point,how can we load the client_ip values into the table.
function populateTable() {
var tableContent = '';
$.get( 'http://localhost:3000/upload', function( data ) {
alert(data);
$.each(data, function(){
tableContent += '<tr>';
tableContent += '<td>' + this.client_ip + '</td>';
tableContent += '</tr>';
});
$('#tablediv').html(tableContent);
});
};
Actually I'm unable to load the data into a html table.Can anyone please help me out regarding this issue.
http://localhost:3000/uploadin$.get. Shouldn't you be specifying completeurlwith extension like$.get('http://localhost:3000/upload.txt'...?http://localhost:3000/uploadwhat are you trying to read fromhttp://localhost:3000/uploadcsvin your script$.eachwill not work.. once you getdataas response try logging by usingconsole.log(data)in console and see how it is obtained