ZX1*_*12R 5 ruby jquery json ruby-on-rails
考虑以下两种情况:
红宝石 1.8.7 导轨 2.3.2
{:a => '<div style="color:red;">asd</div>'}.to_json
?> {"a":"\u003div style=\"color:red;\"\u003Easd\u003/div\u003E"}
Run Code Online (Sandbox Code Playgroud)
当我执行 jQuery.parseJSON() 时,这不会导致任何问题
红宝石 1.8.7 导轨 3.0.9
{:a => '<div style="color:red;">asd</div>'}.to_json
?> {"a":"<div style=\"color:red;\">asd</div>"}
Run Code Online (Sandbox Code Playgroud)
这会导致错误 - JSON.parse:当我执行 jQuery.parseJSON() 时,对象中的属性值后面有预期的 ',' 或 '}'
已尝试以下方法:
没有人在工作。这真是要了我的命啊!
提前致谢。
更新: json 渲染器
render :text => {:success => true, :replacement => '<div style="color:red;">asd</div>'}.to_json
Run Code Online (Sandbox Code Playgroud)
也尝试过
render :json => {:success => true, :replacement => '<div style="color:red;">asd</div>'}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1757 次 |
| 最近记录: |