Javascript 在RJ ERB模板中输出HTML

Javascript 在RJ ERB模板中输出HTML,javascript,ruby-on-rails,ajax,prototypejs,Javascript,Ruby On Rails,Ajax,Prototypejs,这可能真的很愚蠢,但我根本无法让它工作 我有vacation.js.erb,它生成一些javascript,在ajax调用完成时更新页面。文件的源如下所示: $('semantic').replace('<div id="semantic"></div>'); <% html = '<table class="ajax">' html += "<tr><td>EU - 27</td><td>

这可能真的很愚蠢,但我根本无法让它工作

我有vacation.js.erb,它生成一些javascript,在ajax调用完成时更新页面。文件的源如下所示:

$('semantic').replace('<div id="semantic"></div>');
<%
    html = '<table class="ajax">'
    html += "<tr><td>EU - 27</td><td>#{@eu.value.value} days</td></tr>"
    html += "<tr><td>#{@source.location.value}</td><td>#{@source.value.value } days></td></tr>" unless @source.location.value.blank?
    html += "<tr><td>#{@cv.country.name}</td><td>No Data Available</td></tr>" if @source.location.value.blank?
    html += "<tr><td>#{@target.location.value}</td><td>#{@target.value.value } days></td></tr>" unless @target.location.value.blank?
    html += "<tr><td>#{@vacancy.country.name}</td><td>#{@target.value.value } days></td></tr>" if @target.location.value.blank?
    html += "</table>"
%>
$('semantic').insert('<%= escape_javascript(html) %>');
$('semantic')。替换(“”);
$(“语义”)。插入(“”);
我可以用浏览器清楚地浏览代码,但最后一行给我带来了麻烦。它将html中的内容编码为html实体,我不希望这样,因为它破坏了javascript。Fiddler中的响应如下所示:

$('semantic').replace('<div id="semantic"></div>');
<%
    html = '<table class="ajax">'
    html += "<tr><td>EU - 27</td><td>#{@eu.value.value} days</td></tr>"
    html += "<tr><td>#{@source.location.value}</td><td>#{@source.value.value } days></td></tr>" unless @source.location.value.blank?
    html += "<tr><td>#{@cv.country.name}</td><td>No Data Available</td></tr>" if @source.location.value.blank?
    html += "<tr><td>#{@target.location.value}</td><td>#{@target.value.value } days></td></tr>" unless @target.location.value.blank?
    html += "<tr><td>#{@vacancy.country.name}</td><td>#{@target.value.value } days></td></tr>" if @target.location.value.blank?
    html += "</table>"
%>
$('semantic').insert('<%= escape_javascript(html) %>');
$(“语义”)。替换(“”); $('semantic')。插入('EU- 2728 daysgbNo 数据可用性监视 国王领地29 (天);

如何防止页面对html变量进行编码?
我尝试使用但没有返回任何结果。

修复了它,解决方案是

$('semantic').replace('<div id="semantic"></div>');
<%
    html = '<table class="ajax">'
    html += "<tr><td>EU - 27</td><td>#{@eu.value.value} days</td></tr>"
    html += "<tr><td>#{@source.location.value}</td><td>#{@source.value.value } days></td></tr>" unless @source.location.value.blank?
    html += "<tr><td>#{@cv.country.name}</td><td>No Data Available</td></tr>" if @source.location.value.blank?
    html += "<tr><td>#{@target.location.value}</td><td>#{@target.value.value } days></td></tr>" unless @target.location.value.blank?
    html += "<tr><td>#{@vacancy.country.name}</td><td>#{@target.value.value } days</td></tr>" if @target.location.value.blank?
    html += "</table>"
%>
$('semantic').insert('<%=raw html  -%>');
$('semantic')。替换(“”);
$(“语义”)。插入(“”);
在此处找到解决方案: