2017-03-15 1 views
0

당신이 도와 주시겠습니까? 내 코드는 작동하지 않습니다. JS 경고 'succes'하지만 페이지에는 변경 사항이 없습니다.Laravel에서 AJAX가 작동하지 않는다 5.4

경로

Route::post('/more', '[email protected]'); 

jQuery를

$('#moreBtn').click(function() { 

    $.ajax({ 
     method: 'post', 
     url: '/more', 
     data: 'fas', 
     async: true, 
     success: function(){ 
      alert('succes'); 
     }, 
     error: function(data){ 
      console.log(data); 
      alert("fail" + ' ' + this.data) 
     }, 

    }); 
}); 

컨트롤러

감사합니다 0
class IndexController extends Controller 
{ 
public function index(Request $request) 
{ 

    $count = 8; 

    $videos = Video::leftJoin('users', 'videos.user_id', '=', 'users.id') 
     ->select('users.id', 'users.name', 'videos.*') 
     ->orderBy('created_at', 'desc') 
     ->take($count) 
     ->get(); 


    if ($request->ajax()) { 
     $count += 4; 

    } 



    return view('welcome', array(
     'videos' => $videos 
    )); 
} 

} 

내가 말했듯이, 'succes'는 아약스처럼 좋지만 내 페이지는 바뀌지 않습니다.

답변

1

데이터가 변경되지 않으므로 데이터가 변경되지 않습니다. 당신이 아약스 POST 요청을 수행 할 때 귀하의 아약스, 좋은 연습도 유지하고 날엔

로 토큰을 전달 이상과 같은

$.ajax({ 
    method: 'post', 
    url: '/more', 
    data: 'fas', 
    async: true, 
    success: function(response){ 
     alert('succes'); 
     $('body').html(response) // or to the id/class you would like to change 
    }, 
    error: function(data){ 
     console.log(data); 
     alert("fail" + ' ' + this.data) 
    }, 

}); 

그리고 한 가지 더있다한다

관련 문제