Advertisement
Guest User

Untitled

a guest
Aug 17th, 2015
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. client html:-----------------------------------------------------------------
  2. <table id="locationTable" class="display">
  3. <thead>
  4. <tr>
  5. <th>Location Name</th>
  6. <th>Address 1</th>
  7. <th>City</th>
  8. <th>State</th>
  9. <th>Zip</th>
  10. <th>Phone</th>
  11. <th>Fax</th>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. </tbody>
  16. </table>
  17.  
  18. client javascript:-----------------------------------------------------------
  19. $(function() {
  20. $(document).ready( function () {
  21. $('#locationTable').DataTable({
  22. "processing": true,
  23. "serverSide": true,
  24. "ajax": "/locationData",
  25. "length": 10,
  26. "columns": [
  27. { "name": "locationname",
  28. "name": "address1",
  29. "name": "city",
  30. "name": "state",
  31. "name": "zipcode",
  32. "name": "phone",
  33. "name": "fax"
  34. }
  35. ]
  36.  
  37. });
  38. } );
  39. });
  40.  
  41. server javascript:--------------------------------------------------------------
  42. router.get('/', function(req, res, next) {
  43. var sco; // shared connection object;
  44. db.connect()
  45. .then(function (obj) {
  46. sco = obj; // save the connection object;
  47. return sco.query("select * from location order by timestamp desc"
  48. );
  49. })
  50. .then(function (locations) {
  51. if (locations !== undefined) {
  52. res.send(JSON.stringify(locations));
  53. }
  54. }
  55. , function (reason) {
  56. console.log(reason); // display reason why the call failed;
  57. })
  58. .done(function () {
  59. if (sco) {
  60. sco.done();
  61. }
  62. });
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement