2010-04-07 3 views
2

입니다 반환 다운로드 패널 나는 AjaxFileUpload (http://www.phpletter.com/Our-Projects/AjaxFileUpload/) 파일을 업로드 및 struts2에서 JSON 결과 형 응답을 얻기 위해 (code.google.struts2jsonresult.JSONResult)를 사용AjaxFileUpload 데이터가 JSON

하지만 브라우저 항상 팝업 다운로드 창 , PLZ 나에게 몇 가지 제안을주고, 여기에

사전

에 감사 내 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> 

와 JS 클라이언트 :

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

레일에서 루비와 동일한 문제가 있습니다.

나는 반환 헤더는 것을 발견 : 나는이 코드를 사용할 때 ...
render :json => {:error => "", :msg => data} 

그럼 내가 대신 다음 사용하려고 ... "Content-Type을 apllication/JSON"

render :text => {:error => "", :msg => data}.to_json 

반환 헤더가 "Content-Type : text/html"로 변경된 후 문제가 해결되었습니다.

관련 문제