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);        });     } }; 
  1. check console object, because eq. ie console object supply if console window opened
  2. use complete path window.console.

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -