编码数据以发送到javascript

时间:2013-02-09 11:04:31

标签: javascript grails

您好我正在尝试从我的Grails控制器向javascript函数发送数据。我已经使用了escape()但它没有帮助。以下是Fiddler所展示的内容。我想是导致问题的换行符。

控制器:

render(text:content, contentType: "text/javascript")

数据:

addPestMarker( 6, escape('White Fly'), escape('Bemisia tabaci                                 ') ,  escape( 'N/A'), escape(' N/A'), escape('N/A'), escape('Install sticky fly traps.'), escape('Nymph measures to 0.3-0.8mm long. Size is about 1mm long with wings. They possess arrhenotoky where unfertilized eggs produce male flies while fertilized eggs produce female flies. Each female can produce 200 eggs in her life time. For whiteflies, development period takes 30 to 40 days depending on temperature.'), '35.0', '70.0','null', 'null');

1 个答案:

答案 0 :(得分:1)

我相信你需要的是return content as JSON。 Grails会将content序列化为JSON并使用适当的上下文类型。