var CURD = new Object();
CURD = {
del:function(path,id){
//删除操作
if(confirm('确定要删除!')){
$.ajax({
type:'post',
url:'/user/detele/'+path,
id:id,
cache:false,
data:{'id':id},
beforeSend:function(){
$('#mask').show()
},
success:function(d){
if(d.success){
CURD.ms('删除成功')
CURD.ajax_html(path)
}else{
alert("操作失败,请稍后重试!!!");
}
},
error:function(){
alert("操作失败,请稍后重试!!!");
},
complete:function(){
$('#mask').hide()
}
});
}
},
ms:function(text){
//操作后的提示
$('.alert').text(text).fadeIn();
setTimeout(function(){
$('.alert').fadeOut()
},2000);
//加载更新数据
//ajax()
},
ajax_html:function(path){
//操作后异步刷新表格
$.ajax({
type:'get',
url:'/user/ajax/'+path,
cache:false,
success:function(d){
$('#ajax').html(d)
},error:function(){
alert('数据加载失败,请刷新后再操作')
}
})
},
all:function(path){
//批量操作
var id =[]
if(confirm('确定要删除!')){
$('input[name="item"]').each(function(){
if($(this).attr('checked') == 'checked'){
var id = $(this).val()
$.ajax({
type:'post',
url:'/user/detele/'+path,
id:id,
cache:false,
data:{'id':id},
success:function(d){
CURD.ms('删除成功')
CURD.ajax_html(path)
},
error:function(){
alert("操作失败,请稍后重试!!!");
}
});
}
});
}
}
}
打开页面加载数据。
<script type="text/javascript">
CURD.ajax_html('message')
</script>
加载时用图片透明遮罩
/*加载图片*/
#mask{
position: fixed;
_position: absolute;
_top: expression(documentElement.scrollTop + documentElement.clientHeight-offsetHeight);
top:0px;
left:0px;
bottom:0px;
right:0px;
display:none;
}
.loader{
position: fixed;
_position: absolute;
_top: expression(documentElement.scrollTop + documentElement.clientHeight-offsetHeight);
top:200px;
left:50%;
z-index:999;
}
.loader img{
filter:alpha(opacity=30);
-moz-opacity:0.3;
-khtml-opacity: 0.3;
opacity: 0.3;
}
#ajax请求地址
@user.route('/ajax/<path>')
@auth.require(401)
def ajax(path):
if path == 'message':
p = int(request.args.get('p',1))
data = M.Message.search(uid=g.user.mongo_id,page=p,nums=10)
return render_template('user/ajax.html',path=path,data=data)
#删除操作
@user.route('/detele/<path>', methods = ("GET", "POST"))
@auth.require(401)
def detele(path=None):
success = False
if path == 'message':
id = request.form.get('id')
M.Message.get_or_404(id=ObjectId(id)).remove()
success = True
return jsonify({'success':success})