lvgaolong 2012-08-29
ajaxfileupload 异步上传图片返回无法进入error,控制台打印报错如下:
Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'handleError'
主要是jquery版本的问题,需要更高的jquery版本
后来通过想ajaxfileupload.js加入如下代码解决
handleError: function( s, xhr, status, e ) {
// If a local callback was specified, fire it
if ( s.error ) {
s.error.call( s.context || window, xhr, status, e );
}
// Fire the global callback
if ( s.global ) {
(s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
}
}, 如果无法进入success,看看是否是dataType 的类型返回不匹配
我遇到的情况是dataType='json';
后台返回数据代码如下:
Gson gson = new Gson();
Map map = new HashMap();
map.put("photoId", photo.getPhotoId());
map.put("photopath", TargetCommentsPhotopathHelper.getPhotopath_x200(photo.getPath()));
String gsonStr = gson.toJson(map);
PrintWriter out = response.getWriter();
out.print(gsonStr); 这样js会进error,不进success,主要是json返回的数据结构不对,可以让返回正确结构或修改dataType='text';再自行解析
为了美观,把 type="file" 控件隐藏。点击“上传”按钮,click调用隐藏文件控件,再选择文件。查了一遍,好像是ie为了安全控制,文件的必须鼠标点击过后,才能提交。还没有想到其他的方法。。。
5,success 提交成功后自动执行的处理函数,参数data就是服务器返回的数据。6,error 提交失败自动执行的处理函数。7,data 自定义参数。fileElementId: 'file1',
-- 引入相关的js文件,相对路径 -->. -- 执行上传文件操作的函数 -->. method=uploader', //需要链接到服务器地址。fileElementId:'houseMaps',