ajax发送数据防止过快点击重复提交

var havepost = false;
function postcontent(form_data,islayer){
	if(check_login()!==true){	//检查用户登录状态
		return false;
	}
			var that  = ueditor;
			var url = posturl;
			if(pid>0){
				url += '?pid='+pid;
			}
			if(islayer!==true && that.hasContents()==false){
				layer.alert('内容不能为空')
				return false;
			}
			if(havepost==true){
				layer.msg('请不要重复提交');
				return ;
			}
			havepost = true;
            $.post(url, form_data).success(function (res) {
				havepost = false;
                if(res.code==0){
					if(pid>0){
						$('.repalyinfs'+pid).html(res.data);
					}else{
						$('.ListComment').html(res.data);
						//$('.ShowMoreComment').fadeIn();
					}
					//layer.closeAll(); //关闭所有层
					layer.msg('发表成功!');
					//that.hide();
					that.setContent('');					
					//HiddenShowMoreComment();
				}else{
					layer.alert(res.msg);
				}
            }).fail(function () {
				layer.open({title: '提示',content: '服务器发生错误'});
            });            
}

你可能感兴趣的:(每日总结,js)