代码:
css
<style>
.add_ajax{
padding: 10px;
}
</style>
html:
<div class="add_ajax">
<span style="font-size: 12px;font-weight: bold;">新增类型</span>
<input name="name" id="name" class="form-control-ele" value="">
<input type="button" style="padding: 5px;" class="bbtxn add_ajax_func" value="确认添加">
</div>
js:
$(".add_ajax_func").click(function(){
ajax_add_data();
});
//添加数据
function ajax_add_data()
{
var name = $('#name').val()
Ajax.call('contract_koukuan_type.php?act=ajaxAddDo&name='+name, '', function(result){
if(result.error==0){
alert('添加成功');
window.location.reload()
}
else
{
alert(result.message);
}
}, 'GET', 'JSON');
}
php:
elseif($_REQUEST['act'] == 'ajaxAddDo'){
//admin_priv("contract_loan4trim4edit");
$data = [];
$data['name'] = trim($_REQUEST['name']);
$data['add_time'] = get_todaytime();
if(empty($data['name']))
{
make_json_error('类型不能为空');
}
$add_res = db_contract_koukuan_type::addDo($data);
if(!$add_res['status'])
{
make_json_error($add_res['msg']);
}
add_system_log('扣款类型的'.$data['name'], 'add', '', 'log_0217');
make_json_result('', '添加成功', null);
}
function make_json_result($content, $message='', $append=array())
{
make_json_response($content, 0, $message, $append);
}
function make_json_error($msg, $errorcode = 1, $content = '', $go2url = '')
{
make_json_response($content, $errorcode, $msg, array(null), $go2url);
}
//添加数据--入口
static function addDo($data)
{
if(empty($data['name']))
{
return array('status'=>false,'msg'=>'类型名称不能为空','data'=>array());
}
//检查名称是否一样,返回false则不一样,返回true就是存在一样的
$bool = self::checkNameIsEqually(0,'',$data['name']);
//一样,不可以添加
if($bool)
{
return array('status'=>false,'msg'=>'类型名称已存在,不可添加','data'=>array());
}
//不一样,则添加
$res = self::add($data);
if(!$res)
{
return array('status'=>false,'msg'=>'保存失败,不可添加','data'=>array());
}
return array('status'=>true,'msg'=>'','data'=>$data);
}
|