javascript - How can I send my json to my view with node js -
i have previous question take here.
i can login spotify , playlists of user loged in. want send these playlists (they in json) view of html page or ...
this code looks like:
app.get('/playlists', function(req, res) { var state = generaterandomstring(16); res.cookie(statekey, state); var scope = 'playlist-read-private'; var options = { url:"https://api.spotify.com/v1/me/playlists", headers:{ 'authorization': "bearer " + token, 'response_type': 'code', 'client_id': client_id, 'scope': scope, 'state': state }, json:true }; request.get(options, function(error, req, body){ console.log(body); //here want send json view res.send(body); }); });
the problem code "res.send(body);
" url: localhost:8888/playlists , in page see json. send view can chose info show. can me this?
thanks in advance
in case, can use ajax request server library of choice, , when receive data after ajax, update view using data. jquery might like:
var jqxhr = $.get('/playlist', {parameters}); jqxhr.done(function(data){ //data json response can manipulate. });
you might want use res.json() witch more appropriate send json responses in express.
Comments
Post a Comment