ITeye博客

Rails处理ExtJS上传的一个注意事项

crazycode · 2009-07-06 15:24 · Rails · Web前端 · Markdown

在使用ExtJS的上传组件时,我在controller上通过如下代码进行响应:


    render :json => {:success => @attachment.save, :message => 'succ'}.to_json

在上传时,总是出现下载对话框,下载的内容为json内容,十分奇怪,对比网上的例子, 响应基本是一样的,可是为什么别人都可以上传? 这问题搞了一上午,开始怀疑是extjs的一些plugin冲突,去掉一堆plugin后还是如此,后来想起可能是Ajax上传使用了iframe造成的,仔细看了一下ExtJS文档,看到如下内容:

The server response is parsed by the browser to create the document for the IFRAME. If the server is using JSON to send the return object, then the Content-Type header must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.

晕,原来是这样,修改为如下代码:


    render :text => {:success => @attachment.save, :message => 'succ'}.to_json

成功,不再出现下载json的对话框了。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。