AjaxFileUpload return download panel when data is json

无人久伴 提交于 2019-12-07 23:59:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!