node.js - Ajax call on page load in Node application -
trying make ajax call on page load. below code snippet.
in app.js
app.get('/', function(req, res) { res.render('index',{'a':1,'b':2}); //res.send({'a':1,'b':2}); });
in main.js
(function(){ $.ajax({ url: '/' , type: 'get' }) .done(function(data) { console.log(data); }); })();
ovbiously call going wrong here (data coming wrong). can please me understand concept going wrong here ! apreciate .
change app.js so:
app.get('/', function(req, res) { res.json({'a':1,'b':2}); });
Comments
Post a Comment