と、URLからフェッチデータコントローラからの私のビューのデータを引きながら、私は奇妙な行動に気づいた:Laravel 5.4:パラメータ無し
は私が私のルート(web.php)で定義されたこのルートを持っているとしましょう:
Route::get('user/getPageContent/{id}', ['uses'=>'Users\[email protected]', 'as'=>'user.pagecontent']);
今私のDashboardControllerで、私はJSONを返す関数があります。
public function getPageContent($id)
{
$content_model = new Content();
$content = $content_model->getContent($id);
$response = response()->json($content);
return $response;
}
をし、私の見解ではこれを引っ張って、私はjQueryの$のに.getメソッドを使用します。
を$.get('user/getPageContent/'+id, function(response){
//logic goes here
});
これはうまくいきます。私はパラメータなしのURLのために同じ機能を作成した場合、今、私は応答を得ることはありません:
Route::get('user/getAssessmentPage', ['uses'=>'Users\[email protected]', 'as'=>'user.assessmentpage']);
は、コントローラ内の関数を定義します:
public function getAssessmentPage()
{
$content= Assessment_Page::all();
$response = response()->json($content);
return $response;
}
私が取得要求としてルートを作成します
と私の見解ではそれにアクセスしよう:
$.get('user/getAssessmentPage', function(response){
console.log(response);
});
が、私は応答を得ることはありません。レスポンスなし、コンソールにエラーなし、何もありません。私の質問は、表示されているパラメータがないURLの場合、データを取得する方法は何でしょうか?
私はさらに.load
メソッドを試しましたが、依然として応答がないことを述べておきます。
通話は正しく行われますか?たぶん、あなたのコントローラアクションでLog :: info( 'something')を試すことができます – clod986