javascript - Escaping HTML in Ruby & adding to DOM with JS -


i'm trying dynamically add contents of div using js. end ruby on rails. having problem. here's included in view file:

var product_sidebar_inner = "<%= cgi.escapehtml(render(...some partial...)).gsub(/\r/," ").gsub(/\n/," ") %>";

 document.getelementbyid("left_sidebar_wrapper").innerhtml = unescape(product_sidebar_inner); 

the above inserts html text div#left_sidebar_wrapper. spent time on still can't make work. idea am doing wrong?

based on comment macarthy, think want cgi.escape (or cgi.unescape), that's use url encoding. can use uri.escape (or uri.unescape) you'll tired of having pass unsafe regex time want.

also, on javascript side, should using encodeuri or encodeuricomponent escape deprecated because has problems non-ascii characters.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -