2013-01-10 21 views
0

我使用Grails框架中modalbox必須具有以下作用:渲染UTF-8文本與jQuery。員額

def showText() { 
    def myInstace = User.get(params.id) 
    def myText = myService.getText(myInstance.id) 
    render (text: myText, encoding: "UTF-8", contentType: "text/plain") 
} 

上述工程,因爲當我嘗試看到返回的數據精這種方法UDING cUrl作者:我得到的東西,是可以接受的:

沒有捲曲

The (<b>quick</b>) [brown] {fox} jumps! 
Over the $43,456.78 <lazy> #90 dog 
& duck/goose, as 12.5% of E-mail 
from [email protected] is spam. 
Der ,,schnelle」 braune Fuchs springt 
iiber den faulen Hund. Le renard brun 
<<rapide» saute par-dessus le chien 
v ‘$5’ paresseux. La volpe marrone rapida 
「TATVPKOY ‘~35 salta sopra_1l cane pigro. El zorro 

「 marron répido salta sobre el perro 
perezoso. A raposa marrom rzipida 
salta sobre o e50 preguicoso. 

然而,當這對modalbox加載了被看起來像這樣:

The (quick) [brown] {fox} jumps! Over the $43,456.78 #90 dog & duck/goose, 
    as 12.5% of E-mail from [email protected] is spam. Der ,,schnelle」 
    braune Fuchs springt iiber den faulen Hund. Le renard brun < 

我jQuery代碼是很簡單的:

$('a[id^="myText"]').click (function() { 
    $.post($(this).data('url'), function (data){ 
     $("#msg").html(data); 
    }); 
    $('#showText').modal() 
}); 

所以,我似乎無法理解我究竟做錯了什麼?上述內容被加載到一個div中,該div被顯示爲模式框。此外,我config.groovy有UTF-8的設置:

grails.views.gsp.encoding = "UTF-8" 
grails.converters.encoding = "UTF-8" 

回答

1

您的文字自動轉換到HTML格式,這對於<b>, <lazy>, <rapide>爲html代碼,以及<<rapide呈現,有一個格式錯誤。

的解決方案是修改與StringEscapeUtils.unescapeHtml方法的控制器的渲染方法,如:

render (text: StringEscapeUtils.unescapeHtml(myText), encoding: "UTF-8", contentType: "text/plain")