简体   繁体   中英

outputing ruby strings in js.erb file

I am making some ajax call and in my js.erb file I put

$("body").append(<%= escape_javascript(render("layouts/some_layout")) %>);

I had no output in my html file, but in my log, render("layouts/some_layout") is correctly called. So for debugging purpose, I put

 $("body").append(<%= j "<div>test</div>" %>);

But this also output nothin. Why is it so ?

我想您应该将erb代码用引号引起来,否则您可能会收到JS语法错误:

$("body").append('<%= escape_javascript(render("layouts/some_layout")) %>');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM