javascript - how to write custom callback function in js -
i want set message callback after callback of reading file this:
exp.getserverhandler=function (request,response){ if(request.url.startswith("/static/")){ //passing custom callback function input param filereadhandler(request,response,function callback(message){ console.log(message); }); } }; function filereadhandler(request,response,callback){ fs.readfile(request.url.substr(1), function(err,data) { if(err){ response.end("bad request"); response.statuscode=400; //here want set message callback param callback("failed"); }else{ response.end(data); //here want set message callback param callback("successful"); } } ); }
but console didn't log message of callback! problem? correct way of doing this?
edit:
this code works fine , correct
use code:
exp.getserverhandler=function (request,response){ if(request.url.startswith("/static/")){ //passing custom callback function input param filereadhandler(request,response,function callback(message){ if (window.console && window.console.log) window.console.log(message); }); } };
- check console object, because eq. ie console object supply if console window opened
- use complete path
window.console
.
Comments
Post a Comment