javascript - Stuck on a node.js and jquery communication bug. -


here's problem. im working on displaying , manipulating simple mysql database on node.js application. i'm using jquery , bootstrap. know 2 packages referenced in main.handlebars. application home page loads appropriately i'm using render , rendertable function in app.js file display tables have received call database. have confirmed getting data database. receive no errors in developer tools , when bypass app.js , render tables making app.get requests receive correct data.

my problem preventing rendering of tables when load home page. understanding when set $(document).ready(function() function execute when page loaded.

my assumption not communicating in app.js file , preventing render functions executing. novice node.js im overlooking simple not sure is.

app.js render functions

var rendertable = function(url, selector) {   $.ajax({     url: url,     datatype: 'json',     success: function(data) {       $(selector).html('');       $(selector).append('<h3>' + selector.substring(1) + '</h3>' + jsontotable(data, selector.substring(1)));       $(selector).append(composeform(selector, getkeys(data.results[0])));       $(selector + ' .save').on('click', submitentry);       $(selector + ' .delete').on('click', deleteentry);     }   }); }; var render = function() {    console.log(im here!);    rendertable('/artists', '#artists');    rendertable('/country', '#country');    rendertable('/city', '#city');    rendertable('/medium', '#medium');    rendertable('/artists_medium', '#artists_medium');    rendertable('/artists_residence', '#artists_residence');    $('.search').on('click', searchchar); };  $(document).ready(function() {   console.log("app.js reached.");   render(); }); 

server.js requests

var selecttabledata = function(res, table) {   var ctx = {};   pool.query('select * ' + table, function(err, rows, fields) {     if (err) {       console.log(err);       return;     }     ctx.results = rows;     res.send(ctx);   }); };  app.get('/artists', function(req, res) {   selecttabledata(res, 'artists'); });  app.get('/country', function(req, res) {   selecttabledata(res, 'country'); });  app.get('/city', function(req, res) {   selecttabledata(res, 'city'); });  app.get('/medium', function(req, res) {   selecttabledata(res, 'medium'); });  app.get('/artists_medium', function(req, res) {   selecttabledata(res, 'artists_medium'); });  app.get('/artists_residence', function(req, res) {   selecttabledata(res, 'artists_residence'); }); 

theses of course snippets of larger project.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -