Saturday, 15 August 2015

Node.js Express: Ajax call from ejs to app.js fetching data render div dynamically -



Node.js Express: Ajax call from ejs to app.js fetching data render div dynamically -

i have express app node.js that,

1) app.get('/', routes.index) points index.ejs.

2) there button on index.ejs. when clicked, want phone call datagrab function in app.js retrieve info remotely , display in index.ejs <table> dynamically.

in app.js

var data=[]; grab = function() { .... grab info remotely , force data[] }

as button sits on client side, if want phone call grab() in app.js populate data[] , utilize render table on index.ejs, using ajax way? if yes, u share simple code sample?

regards hammer

thanks tymejv, sends using code below ,

* edit add together ajax call

inside of ejs using

<script> $.get('/grab',function(data) { for(var h=0; h<data.length;h++){ $('#newsitemtable').append('<tr><td>'+data[h].name+'</td></tr>'); } }); </script>

while in app.js m using

app.get('/grab', function(req, res) { .... res.send(data); }

ajax node.js express ejs

No comments:

Post a Comment