用layui的上传组件,或者用ajax上传文件,经常会出现文件被重复上传了,就点了一下,正在解析excel数据入库的时候,在这个过程中,请求又被提交了,我们前端用的是ajax,中间用的是nodejs,经过测试,在nodejs 路由这一层就被请求了两次。
OST /channel/channel_recruit_report_service/importpeportpersonnel/import?pro_id=277537008741126144&mark=1645177370509-274934461517402112 - - ms - -
POST /channel/channel_recruit_report_service/importpeportpersonnel/import?pro_id=277537008741126144&mark=1645177370509-274934461517402112 200 1031.975 ms - 82
连续请求了两次,第一次没有状态,没有用时,第二次是200 还有1多秒的时间
前端代码用了最简单的ajax提交文件
$.ajax({
type: 'POST',
url: '<%=url_prefix%>/channel_recruit_report_service/importpeportpersonnel/import?pro_id=' + proId + '&mark=' + mark,
data:formData,
cache: false, // 不缓存
processData: false, // jQuery不要去处理发送的数据
contentType: false, // jQuery不要去设置Content-Type请求头
success: function (res){
if (res.isSuccess) {
toImportPage();
}else{
// if(res.code!='repeat_request'){
//如果错误信息是这样的,说明导入过程中出现了未知错误,程序终止
if(res.code.indexOf("行:error_065")!=-1){
var errorCode = res.code.split(":");
layer.msg("导入到第"+errorCode[0]+"出现未知错误,"+promptJson[res.code], {icon: 2, time: 5000, shade: 0.1});
}else{
layer.msg(promptJson[res.code], {icon: 2, time: 3000, shade: 0.1});
}
// }
}
layer.closeAll();
},
error:function(){
},
dataType: "json",
async: true
});
请老手们给看看这是啥问题造成了,多谢
和这段代码没关系,是你们的button控件调用的问题,给页面添加busy机制,在点击一次的时候就设置成busy。
当连续点击的时候
第一次成功调用后台,然后设置成busy;
第二次因为控件时busy,所以就不会再到后台了