一个Ajax的小示例

2016-08-01  本文已影响0人  ImpotentRage
<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方式路由

上一篇 下一篇

猜你喜欢

热点阅读