jquery.ajaxfileupload.js 问题汇总

1、运行时报:jQuery.handleError is not a function 错误.

这个错误是由于ajaxfileupload.js 是在jquery1.4.2版本之前写的,Jquery之后的版本已经没有了handleError 方法,所以可以将1.4.2版本中的该方法复制到该ajaxfileupload.js中。

// handleError 方法在jquery1.4.2之后移除了,此处重写改方法
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] );
    }
}
2、执行成功后,始终指向error方法处理,无法执行sucess方法
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody 
String upload(HttpServletResponse response, MultipartFile file) {
    response.setContentType("text/html;charset=UTF-8");     //*****
    Map<String, String> result = new HashMap<String, String>();         
    try {
        String url = fileService.upload(file);
        result.put("type", "success");
        result.put("url", url);
    } catch (Exception e) {
        log.error("shop upload image error! ", e);
        result.put("type", "error");
    }
    return JSON.toJSONString(result);
}

参考

AJAX File Upload github site
无刷新文件上传之二:Jquery文件上传插件–ajaxfileupload
ajaxfileupload.js问题汇总及解决 附修复版下载
jquery插件–ajaxfileupload.js上传文件原理分析
jQuery插件之ajaxFileUpload
SpringMVC+ajaxfileupload文件上传返回json下载?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章