分享

ajaxfileupload 异步上传图片返回无法进入success,error

 瑶疏影 2016-02-16

ajaxfileupload 异步上传返回无法进入error,控制台打印报错如下:

Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'handleError'

主要是jquery版本的问题,需要版本是1.4.2之前的jquery版本(解决方法请参看位于JQuery文件夹下的文章:ajaxFileUpload 报这错jQuery.handleError is not a function

后来通过想ajaxfileupload.js加入如下代码解决

Js代码  收藏代码
  1. handleError: function( s, xhr, status, e ) {  
  2.     // If a local callback was specified, fire it  
  3.     if ( s.error ) {  
  4.         s.error.call( s.context || window, xhr, status, e );  
  5.     }  
  6.     // Fire the global callback  
  7.     if ( s.global ) {  
  8.         (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );  
  9.     }  
  10. },   
 

 

如果无法进入success,看看是否是dataType 的类型返回不匹配

我遇到的情况是dataType='json';

后台返回数据代码如下:

 

Java代码  收藏代码
  1. Gson gson = new Gson();  
  2.   
  3. Map map = new HashMap();  
  4.             map.put("photoId", photo.getPhotoId());  
  5.             map.put("photopath", TargetCommentsPhotopathHelper.getPhotopath_x200(photo.getPath()));  
  6.               
  7.             String gsonStr = gson.toJson(map);  
  8.             PrintWriter out = response.getWriter();  
  9.             out.print(gsonStr);  
 

这样js会进error,不进success,主要是json返回的数据结构不对,可以让返回正确结构或修改dataType='text';再自行解析


以上来自:http://yangjayup./blog/1667094

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多