当数据是JSON AjaxFileUpload返回下载面板 [英] AjaxFileUpload return download panel when data is json

查看:142
本文介绍了当数据是JSON AjaxFileUpload返回下载面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用AjaxFileUpload(http://www.phpletter.com/Our-Projects/AjaxFileUpload/)上传文件并获得Struts2的(code.google.struts2jsonresult.JSONResult)

但是浏览器总是弹出下载窗格中,PLZ给我一些建议,在此先感谢

下面是我在struts.xml中的配置:

  ......

<结果类型名称=JSON级=code.google.struts2jsonresult.JSONResult>

............


<作用NAME =doGetList方法=doGetList
类=main.java.GetListAction>

   <结果类型=json的>
    < PARAM NAME =目标>的JSONObject< /参数>
    < PARAM NAME =deepSerialize>真< /参数>
    < PARAM NAME =模式> -  *类和LT; /参数>
   < /结果>
  < /作用>
 

和JS客户端:

 函数ajaxFileUpload(){



    $(#加载)。ajaxStart(函数(){

              $(本).show();

       })。ajaxComplete(函数(){

           $(本).hide();
       });

    $ .ajaxFileUpload
    (
     {
      网址:doGetList.do,
      secureuri:假的,
      fileElementId:uploadfile,
      数据类型:JSON,
      成功:功能(数据,状态)
      {

       如果(typeof运算(data.error)!=未定义)
       {
        如果(data.error!='')
        {
         警报(data.error);
        }
        其他
        {
         警报(data.msg);
        }
       }
      },
      错误:功能(数据,状态,E)
      {
       警报(E);
       警报(data.records);

      }
     }
    )

  返回false;

 }
 

解决方案

我在Ruby on Rails的同样的问题。

我注意到,返回标题是:当我用这个code的内容类型apllication / JSON......

 渲染:JSON => {:错误=> :味精=>数据}
 

然后我试图用下面的,而不是...

 渲染:文本=> {:错误=> :味精=>数据} .to_json
 

之后,返回头改为内容类型:text / html的,那么问题就解决了​​。

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;

 }

解决方案

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.

这篇关于当数据是JSON AjaxFileUpload返回下载面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆