问题
I use AjaxFileUpload (http://www.phpletter.com/Our-Projects/AjaxFileUpload/ ) to upload a file and get json result type response in struts2 ( code.google.struts2jsonresult.JSONResult )
but browser always pop-up download pane, plz give me some suggestions, thanks in advance
Here is my config in struts.xml :
......
<result-type name="json" class="code.google.struts2jsonresult.JSONResult">
............
<action name="doGetList" method="doGetList"
class="main.java.GetListAction">
<result type="json">
<param name="target">jsonObject</param>
<param name="deepSerialize">true</param>
<param name="patterns"> -*.class</param>
</result>
</action>
and js client :
function ajaxFileUpload(){
$("#loading").ajaxStart(function(){
$(this).show();
}).ajaxComplete(function(){
$(this).hide();
});
$.ajaxFileUpload
(
{
url:'doGetList.do',
secureuri:false,
fileElementId:'uploadfile',
dataType: 'json',
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
}
else
{
alert(data.msg);
}
}
},
error: function (data, status, e)
{
alert(e);
alert(data.records);
}
}
)
return false;
}
回答1:
I have the same problem in ruby on rails.
I noticed that the return header was "Content-Type: apllication/json" when I used this code...
render :json => {:error => "", :msg => data}
Then I tried to use the following instead...
render :text => {:error => "", :msg => data}.to_json
After that the return header was changed to "Content-Type: text/html", then the problem solved.
来源:https://stackoverflow.com/questions/2590335/ajaxfileupload-return-download-panel-when-data-is-json