Rails JS 解析 XML 路径问题

liker · December 17, 2013 · Last by liker replied at December 18, 2013 · 2515 hits

在 html.erb 文件中 如果 xml 文件在 public 目录下,js 就能解析 xml

<script>
    var path = '../a.xml';
    var  xmlDocSave = loadXmlFile(path);
</script>

当把 xml 文件放到 views 目录下时

<script>
    var path = 'app/views/template/a.xml';
    var  xmlDocSave = loadXmlFile(path);
</script>

type 为 text/html 而不是 application/xml 了。 求大神帮忙!

Rails 跑起来的时候 JS 能访问的只有 public 目录下面的东西 这意思和你直接用浏览器打开那个 XML 的道理是一样的,你得分清前端和后端

#1 楼 @huacnlee 恩,配置了一下路由。加上 format: 'xml' 就能访问了

You need to Sign in before reply, if you don't have an account, please Sign up first.