jquery - append HTML from file with Cheerio, NodeJs -



jquery - append HTML from file with Cheerio, NodeJs -

i trying append html file existing html cheerio maintain getting errors (the errors beingness produced cheerio library debugging hard)

expo.includenav = function(html, result) { var file = 'templates/admin_nav.html'; fs.readfile(file, function(err, nav) { var $ = cheerio.load(html); $('body').append(nav); result($.html()); }); }

it dosen't seem passing variable append function.

if set html in instead of calling file works, so:

$('body').append('<div class="nav"> navigation list here</div>');

but not want want front end end devs able edit html file instead of digging node js code find alter html.

i'v worked out. assume else may run issue see beingness mutual need. here answer.

you need specify want returned string instaed of buffer. 'utf8'

expo.includenav = function(html, result) { var file = 'templates/admin_nav.html'; fs.readfile(file, 'utf8', function(err, nav) { var $ = cheerio.load(html); $('body').append(nav); result($.html()); }); }

jquery html node.js append cheerio

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -