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

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -