使用webuploader插件做导入,不懂为什么后台控制器会进入两次!
前台:
上传工具方法
/**
- 导入工具类
- Created by huangli on 2017/08/10
*/
define(function (require, exports, module) {
var defaultOptions = {
swf: staticWebUrl + '/lib/webuploader/v0.1.5/Uploader.swf',
auto : true, //自动上传
// auto : false, //用户控制上传时机
fileVal : "file",
fileNumLimit : 1,
duplicate : false,
server : webRoot + "import/imStClinic",
//按钮
pick : {
//按钮ID
id : "#importBtn",
//按钮文字
innerHTML : "导入",
//按钮是否支持多选,默认不支持
multiple : false
},
//允许的文件格式
accept : {
title : "Excel",
extensions : "xlsx,xls",
mimeTypes : "application/xls,application/xlsx"
}
};
var internal = {
init : function(options){
var uploadOptions = $.extend(true, {}, defaultOptions, options);
var uploader = WebUploader.create(uploadOptions);
//添加文件错误
uploader.on( 'error', function(type, file) {
if (type == "Q_EXCEED_NUM_LIMIT") {
//该错误的file为undefined
type = "文件数量超出限制,最多" + uploader.options.fileNumLimit + "个!";
} else if (type == "Q_EXCEED_SIZE_LIMIT") {
type = "文件大小超出限制!";
} else if (type == "Q_TYPE_DENIED") {
type = "文件类型错误!请选择" + uploader.options.accept[0].extensions;
} else if (type == "F_DUPLICATE") {
type = "文件重复!";
} else if (type == "Q_FILE_CANNOT_BE_EMPTY") {
type = "文件内容不能为空!";
}
common.jsmsgError(type);
});
// 文件上传失败
uploader.on( 'uploadError', function(file , response) {
//common.jsmsgError("导入失败,错误编码:" + response + "!");
common.jsmsgError("导入失败!");
});
//当所有文件上传结束时触发
uploader.on('uploadFinished',function(file, response){
uploader.reset();
});
// 文件上传成功,给item添加成功class, 用样式标记上传成功。
uploader.on( 'uploadSuccess', function( file , response) {
//导入不需要写
});
//上传返回值
uploader.on("uploadAccept", function(file, response){
//错误信息在这里提示
if (response.isSuccess) {
common.jsmsgSuccess("导入成功");
} else {
var errorMsg;
if ( response.messages && response.messages.length > 0) {
$.each(response.messages, function (index, item) {
errorMsg += item["content"]
});
}
common.jsmsgError(errorMsg);
}
});
//当有文件添加进来时
/* uploader.on("fileQueued", function(file, response){
common.confirm("是否上传文件", function(){
uploader.upload();
},function(){
uploader.reset();
});
//common.jsmsgSuccess("文件上传成功");
});
*/
}
};
exports.init = function (options) {
return internal.init(options);
};
});
后台代码:
不懂为什么每次导入文件,控制器都会进入两次,求教各位,谢谢!
因为开启了断点续传 关闭就行了