PHP:【ThinkPHP】=> 通用后台管理,用户名,头像,判断是否为空
HTML 代码块
//图片上传 js方法
function save(){
$.post("{$config['admin_route']}Jz/user_add",$('form').serialize(),function(res){
switch (res.id) {
case 0:
layer.msg(res.msg,{'icon':2});
break;
case 1:
layer.msg(res.msg,{'icon':1});
setTimeout(function(){parent.window.location.reload();},1000);
break;
case 2:
layer.msg(res.msg,{'icon':2});
break;
default:
layer.msg(res.msg,{'icon':2});
break;
}
},'json');
}
PHP 代码块
public function user_add()
{
//用户添加
//判断是否是post 提交 是的话再输出
if (Request::isPost()) {
$name = Request::post('name');
$img = Request::post('test_img');
//判断名称和头像是否为空
if (empty($name) || empty($img) ) {
echo json_encode(['id'=>2,'msg'=>'名称和图片不能为空']);
return; //结束判断
}else {
//执行数据插入数据库
$insert = Db::table('xmjz_user')->insert([
'name' => $name,
'img' => $img,
'status' => 1
]);
}
//判断是否插入成功,数据返回给前端
if (!empty($insert)) {
echo json_encode(['id' => 1,'msg'=>'成功']);
}else {
echo json_encode(['id'=>0,'msg'=>'失败']);
}
}else {
return View::fetch();
}
}
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!