在使用ajaxFileUpload上传文件时,Chrome没问题,IE和Firefox出错,Firefox报SyntaxError: Syntax error错误
JS代码如下:
$.ajaxFileUpload( {
url : 'FileUpload.do',secureuri : false,fileElementId : 'imgFile',dataType : 'json',success : function(data,status) {
//...
},error : function(data,status,e) {
alert(e);
}
})
我们可以看到dataType返回值为json,而后台却没有返回json数据所以报错
后台加上如下代码,返回前台需要的数据
PrintWriter out =response.getWriter();
out.println("{msg:1,name:'" + name + "',id:'" + id + "'}"); //返回JSON
out.close();
此错误为特定情况下产生的,不一定有共性,供参考。