Sunday, 15 September 2013

node.js - Node Pass Hidden Data To Other Route -



node.js - Node Pass Hidden Data To Other Route -

i have route in express(item/update/), , after happens want send them /, want create / show alert 'success' or 'failure'. don't want utilize query string or hash because want hidden user. don't want render / @ items/update seems bad idea. also, have tried javascript history api, seems hack history api else.

please allow me know if there more info need.

you can couple of ways,

1.you can redirect "/" url query string. since don't add together info in query string, alternate alternative session.

for example,

function itempupdatehandler(request,response){ //do stuff request.session.displaymsg = "update done successfully"; response.setheader("location: http://yourdomain.com/"); response.end(); } function homepagehandler(request,response){ //display message here read session. if(request.session.displaymsg){ console.log(request.session.displaymsg); delete request.session.displaymsg; } //do regular suff here. }

2.you have take care more in next method, here aren't going redirect need modify handler function follows,

function itempupdatehandler(request,response){ //do stuff //response.setheader("location: http://yourdomain.com/"); //no need here homepagehandler(request,response, {display:true, msg: "update done successfully"}); } function homepagehandler(request,response, moreargs){ //display message here read session. if(moreargs.display){ console.log(moreargs.msg); } //do regular suff here. }

note: assumed using express

node.js express routes hidden

No comments:

Post a Comment