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

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -