此解决方案不起作用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"}
答案 0 :(得分:0)
你可以尝试一下,看看
$("#toTest").val($("<div/>").html("hello this is sireesha \r\n 1. hello \r\n 2. hello2 ").text());
小提琴