在使用ExtJS的上传组件时,我在controller上通过如下代码进行响应:
在上传时,总是出现下载对话框,下载的内容为json内容,十分奇怪,对比网上的例子, 响应基本是一样的,可是为什么别人都可以上传?
这问题搞了一上午,开始怀疑是extjs的一些plugin冲突,去掉一堆plugin后还是如此,后来想起可能是Ajax上传使用了iframe造成的,仔细看了一下ExtJS文档,看到如下内容:
[quote]
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.
[/quote]
晕,原来是这样,修改为如下代码:
成功,不再出现下载json的对话框了。
render :json => {:success => @attachment.save, :message => 'succ'}.to_json
在上传时,总是出现下载对话框,下载的内容为json内容,十分奇怪,对比网上的例子, 响应基本是一样的,可是为什么别人都可以上传?
这问题搞了一上午,开始怀疑是extjs的一些plugin冲突,去掉一堆plugin后还是如此,后来想起可能是Ajax上传使用了iframe造成的,仔细看了一下ExtJS文档,看到如下内容:
[quote]
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.
[/quote]
晕,原来是这样,修改为如下代码:
render :text => {:success => @attachment.save, :message => 'succ'}.to_json
成功,不再出现下载json的对话框了。