Rolling with Rails 2.0 - Part 2(中文)
2008-03-05 23:23
579 查看
![]() Appfuse框架中的Ajax ![]() Appfuse中使用了Sitemesh模块对请求进行封装,默认配置一般为: <sitemesh> <property name="decorators-file" value="/WEB-INF/decorators.xml"/> <excludes file="${decorators-file}"/> <page-parsers> <parser default="true" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/> <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/> <parser content-type="text/html;charset=UTF-8" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/> </page-parsers> <decorator-mappers> <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper"> <param name="config" value="${decorators-file}"/> </mapper> </decorator-mappers> </sitemesh> Ajax请求一般要求responseText为简单文本或者XML文本。数据量较少时采用无格式简单文本;如果数据量比较大,通常采用XML数据。 后一种情况下,需要在处理Ajax请求的Action中,设置 response.setContentType("text/xml;charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); 然后创建输出流对象并response数据: PrintWriter out = response.getWriter(); out.println("<?xml version='1.0' encoding='UTF-8'?>"); out.println("<root>"); out.println("<result>"); ...... out.close(); 如果是在Appfuse框架下使用的Ajax,就要避免response被Sitemesh封装起来,变成了HTML文本(表现在浏览器端,应该会得到Sitemesh的修饰文件,内嵌了response文本) 解决方法是修改decorators.xml中的配置将处理Ajax的Action排除到默认修饰以外。 ![]() |
相关文章推荐
- Rolling with Rails 2.0 - The First Full Tutorial - Part 2
- Rolling with Rails 2.0 - The First Full Tutorial (中文)
- Rolling with Rails 2.0 - The First Full Tutorial - Part 1
- [ROR]Single Table Inheritance with Rails 4 (Part 1)
- [ROR]Single Table Inheritance with Rails 4 (Part 2)
- Rolling On Rails With RubyStack
- [ROR]Single Table Inheritance with Rails 4 (Part 3)
- DPM2010中文翻译-Object Detection with Discriminatively Trained Part Based Models
- JavaScript with ASP.NET 2.0 Pages - Part 1
- Beginning OpenGL ES 2.0 with GLKit Part 1
- Get started with Docker 中文文档(2)——Part 2: Containers
- Rolling with Ruby on Rails
- Get started with Docker 中文文档(3)—— Part 3: Services
- Tutorial: Storyboard in XCode 4.2 with Navigation Controller and Tabbar Controller (Part 2)(中文注解)
- Get started with Docker 中文文档(1)——Part 1: Orientation and Setup
- Building Dynamic Web 2.0 Websites with Ruby on Rails
- Rails中文Podcasts【四】
- Asm Shader Reference --- Shader Model 2.0 part
- Work with XML Data Type in SQL Server 2005 from ADO.NET 2.0
- Deep learning with Theano 官方中文教程(翻译)(四)—— 卷积神经网络(CNN)