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

Popular posts from this blog

command line - Use qwinsta in PowerShell ISE -

java - Incorrect order of records in M-M relationship in hibernate -

Python website log in: BIG-IP can not find session information in the request -