R5q7p
R5q7p
2016-07-11 13:53

ajaxfileupload+servlet实现文件上传,返回json对象,前台解析是doc

ajaxfileupload+servlet实现文件上传,返回json对象,前台解析为document对象,而不是xhr

前台ajax

<input type="file" name="myImage" id="myImage" onchange="uploadImage()">
<script>
        function uploadImage(){
            $.ajaxFileUpload({
                url : '${pageContext.request.contextPath}/servlet/UploadHandleServlet',
                secureuri: false,
                fileElementId : 'myImage',
                dateType : 'JSON',
                success:function(data){
                    //返回内容undefined
                    alert(data.msg);
                    //$("#imgSrc").val(data.msg);
                }
            });
        }
    </script>

后台servlet返回json

        ReturnValue rv=new ReturnValue(1,"upload/"+saveFilename);
    String res = JSONObject.fromObject(rv).toString();
    System.out.println(res);
    PrintWriter pw = response.getWriter();
    pw.print(res);

后台打印的json
{"err":1,"data":null,"msg":"upload/5c639295-c0af-4d9e-bfbf-b8d5c3d8e81d_youj.sql"}
图片说明

图片说明

返回的data.msg为undefined,求解

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换