Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- client html:-----------------------------------------------------------------
- <table id="locationTable" class="display">
- <thead>
- <tr>
- <th>Location Name</th>
- <th>Address 1</th>
- <th>City</th>
- <th>State</th>
- <th>Zip</th>
- <th>Phone</th>
- <th>Fax</th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- client javascript:-----------------------------------------------------------
- $(function() {
- $(document).ready( function () {
- $('#locationTable').DataTable({
- "processing": true,
- "serverSide": true,
- "ajax": "/locationData",
- "length": 10,
- "columns": [
- { "name": "locationname",
- "name": "address1",
- "name": "city",
- "name": "state",
- "name": "zipcode",
- "name": "phone",
- "name": "fax"
- }
- ]
- });
- } );
- });
- server javascript:--------------------------------------------------------------
- router.get('/', function(req, res, next) {
- var sco; // shared connection object;
- db.connect()
- .then(function (obj) {
- sco = obj; // save the connection object;
- return sco.query("select * from location order by timestamp desc"
- );
- })
- .then(function (locations) {
- if (locations !== undefined) {
- res.send(JSON.stringify(locations));
- }
- }
- , function (reason) {
- console.log(reason); // display reason why the call failed;
- })
- .done(function () {
- if (sco) {
- sco.done();
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement