【发布时间】:2015-12-18 23:20:18
【问题描述】:
这个解决方案不起作用displaying stored data in textarea.. 你能检查我的代码,让我知道有什么问题吗?
在 Ruby 中,我有一个处理程序,它将从数据库中获取加密数据并解码并发送到 jquery 函数,该函数将在下拉表更改时在 textarea 上显示来自数据库的文本
Ruby code:
get '/show_previousdata' do
projectName=params[:name]
record=Array.new
description=Array.new
record=Project.filter(:project_name=>projectName).first
project_id=record[:projects_id]
description=Highlight.filter(:projects_id=>project_id).first
if description==nil
highlight="no data"
else
highlight=Zlib::Inflate.inflate(description[:description])
end
highlight.to_json
end
Jquery code:
$("#project_list").change(function () {
var index = $(this).find("option:selected").index();
var text_val = $(this).find("option:selected").text();
if(index!=0)
{
$.get('/show_previousdata',
{
name:text_val
},
function(data,status){
$("#text_area").val($("<div/>").html(data).text());
});
$('#highlights_textarea').show();
}
else
{
$('#highlights_textarea').hide();
}
});
haml code:
%textarea{:id => "text_area",:cols => "20", :rows => "20",:class => "textarea1"}
【问题讨论】:
-
你能解释一下你所面临的问题吗?
-
我无法以我在该链接中提到的正确格式显示文本(来自数据库)...(stackoverflow.com/questions/32471160/…)
-
当你做一个 console.log(data) 你得到什么价值?
-
我以这种格式获取数据“你好,这是sireesha\n 1.some information \n2.some information”
-
你可以试试下面的答案看看
标签: jquery html ruby json postgresql