2016-09-22 15 views
0

에 jQuery를 사용하여 경로에 데이터를 전달하는 방법이Laravel

Route::get('user/{id}/article', '[email protected]')->name('Show'); 

같은 경로가 그리고 인식은`t JQuery와에게

$('.user').click(function() { 
    var id = $(this).attr('data-id'); 
    window.location.href ='{{ route('Show',['id'=> id]) }}'; 
}); 

그러나 id를 사용하여 매개 변수 ID를 전달해야 , 어떻게해야합니까?

+0

처럼 HTML 링크 나에게 HTML 코드 – Komal

답변

0

당신은 다음과 같은 코드 값을 전달할 수 있습니다 : [

  <script type="text/javascript"> 
      $('#modal-save').on('click',function(){ 
       $.ajax({ 
        type : 'post', 
         url : urlEdit, 
         data : {body : $('#post-body').val(), postId: postId , _token:token } 
       }).done(function(msg){ 
       //console.log(msg.new_body); 
        $(PostBodyElement).text(msg['new_body']); 
        $('#edit-modal').modal('hide'); 
     }); 
    }); 
       </script> 

이것은 컨트롤러에 공공 기능 postEditPost (요청 $ 요청) { $ this-이>의 validate ($ 요청해야 를 ' body '=>'required ' ]); $ post = Post :: find ($ request [ 'postId']); if (Auth :: user()! = $ post-> user) { return redirect() -> back(); } $ post-> body = $ request [ 'body']; $ post-> update(); return response() -> json ([ 'new_body'=> $ post-> body], 200); }

우르 경로에서 : 루트 :: 포스트 ('/ 수정'[ '사용'=> 'PostController @ postEditPost' '로서'=> '수정' ]);

0

그것은 이름으로 경로를 호출 할 수있는이

<a href="user/{{ $user->id }}/article">{{ $user->name }}</a> 
+0

을주십시오 생성하는 것입니다 시도? URL을 사용하지 않습니다. – Fan

+0

예,하지만 당신이 원하는 URL을 설명 plz. – Komal