封装的ajax:
function ajaxJson(url,data,callfun) { $.ajax({ type:"POST", url:url, data:data, dataType:‘json‘, success:callfun, error:function(){ $(‘.modal-body‘).html(‘参数丢失,请重新操作一次‘); $(‘#myModal‘).modal(‘show‘); }, }); }
使用实例:
$(‘.button_del‘).click(function(){ var book_id = $(this).attr(‘book_id‘); var own_id = $(this).attr(‘own_id‘); var type = 2; //删除 if(!book_id || !own_id){ $(‘.modal-body‘).html(‘部分参数丢失‘); $(‘#myModal‘).modal(‘show‘); return false; } $(this).attr(‘disabled‘,"true"); //添加disabled属性 var url = "<?php echo $this->url->get(‘index/dealmyrequest‘);?>"; var data = "book_id="+book_id+"&own_id="+own_id+"&type="+type; ajaxJson(url,data,function(res){ $(‘.modal-body‘).html(res.msg); $(‘#myModal‘).modal(‘show‘); $(‘#myModal‘).on(‘shown.bs.modal‘,function(e){ $(‘.button_del‘).removeAttr("disabled"); //移除disabled属性 }); if(res.flag==1){ $(‘#modal_confirm‘).click(function(){ window.location.reload(); }); // //模态框show 完后的回调函数 // $(‘#myModal‘).on(‘shown.bs.modal‘,function(e){ // window.location.reload(); // }); } }); return false; });
时间: 2024-10-24 15:26:09