Jquery 如何在javascript响应中包含html代码的字符串变量?
在我的控制器的ShowAction中,我们准备了一组信息,用于构建一个html表,该表通过jquery替换表所在的div返回到浏览器 这一部分被解释为纯文本,而不是添加到表中。我推测,我的编码有问题,但迄今为止我所做的尝试并没有改善结果 控制器的显示动作部分:Jquery 如何在javascript响应中包含html代码的字符串变量?,jquery,html,ajax,ruby-on-rails-4,Jquery,Html,Ajax,Ruby On Rails 4,在我的控制器的ShowAction中,我们准备了一组信息,用于构建一个html表,该表通过jquery替换表所在的div返回到浏览器 这一部分被解释为纯文本,而不是添加到表中。我推测,我的编码有问题,但迄今为止我所做的尝试并没有改善结果 控制器的显示动作部分: @shared_individuals = Individual.where(:address_id => params[:id]).order("birthdate ASC") @typecodes = Contactmethod
@shared_individuals = Individual.where(:address_id => params[:id]).order("birthdate ASC")
@typecodes = Contactmethods.select("Distinct typecode_desc, typecode_id")
@contact_methods = getem( @typecodes, @shared_individuals)
getem()是控制器中的一个函数,它对表进行了大量的毛茸茸的排列和html编码,但为了简化并找出问题所在,目前只需执行以下操作:
def getem( @typecodes, @shared_individuals )
foo = "<tr><td>Testing</td></tr>"
return foo
end
为什么不:
@contact_methods + #that blows up the javascript processing
我用另一种方式解决了这个问题,这种方式更符合MVC约定:控制器创建视图所需的所有数据的集合,但不将其包装为HTML。分部完成所有HTML包装。然后注意和之间的区别也总是聪明的
< tr>< td>Testing< /td>< /tr>
'<%=h @contact_methods %>' + #wasn't that from Rails 1.0?
'<%= @contact_methods %>' + #nothing shows up
'#{@contact_methods}' + #but of course that's silly in this context
@contact_methods + #that blows up the javascript processing