ajaxfileupload.js在SpringMVC中使用笔记

1.页面代码

<input type="file" id="file" value="" name="file" value="请选择" width="60px" οnchange="changePhoto()" />

2.js

   function ajaxFileUpload(file){
         $.ajaxFileUpload(
          {
         url:'${pageContext.request.contextPath}/file.do?method=fileUpload',            //需要链接到服务器地址
         secureuri:false,
         fileElementId:'file',//文件选择框的id属性
         type:'post',                     
         dataType: 'json', 
         data:{file: file},                          //服务器获取文件的名称
         success: function (data, status)            
        {   
         console.debug("添加成功"+data.result+","+status);
         },
         error: function (data, status, e)            
         {
            alert("添加失败!");
         }
        });
         
      
    }
function changePhoto(){
var file =$("#photoPath_view").val();
ajaxFileUpload(file);
}

3.上传结果

       //返回上传结果
String res = "{ status:'" +1 + "', result:'" + fileNum + "',imgurl:'" + path + "'}";

        response.getWriter().write(res);


总结:1.from中不能嵌套form;

             2.使用ajaxfileupload.js时会引用jquery中的handleError(),但是版本大于1.4.2的jquery中取消了该方法.

           解决方法:(1).使用低版本的jquery;

                              (2)将下列代码加入ajaxfileupload.js中;

                  handleError: function( s, xhr, status, e ) {
// If a local callback was specified, fire it
if ( s.error ) {
s.error.call( s.context || s, xhr, status, e );
}


// Fire the global callback
if ( s.global ) {
(s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
}
},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值