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下載?

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