<script>
function clock(user_id,user_name){
$.post("{{url('clock')}}",
{
_token:'{{csrf_token()}}',//防CSRF攻击
id:user_id,
name:user_name
}, function(res){
if( res.code==0 ){
alert(res.msg);
location.href = location.href;
}else{
alert(res.msg);
}});
}</script>
public function clock(){
$input = Input::all();
$user = User::find( $input['id'] );
$user['user_realname'] = $input['name'];
$res = $user->update();
if( $res ){
$res = [
'code'=>0,
'msg'=>'成功!',
];
}else{
$res = [
'code'=>1,
'msg'=> '失败!',
];
}
return $res;
}
Laravel需要为clock分配POST方式路由
网友评论