mercredi 7 juin 2017

Laravel 5.4: fetching data from url with no parameter

I have noticed a strange behaviour while pulling data in my view from the controller:

Lets say i have this route defined in my routes(web.php):

Route::get('user/getPageContent/{id}', ['uses'=>'Users\DashboardController@getPageContent', 'as'=>'user.pagecontent']);

Now in my DashboardController, i have the function that returns the json:

public function getPageContent($id) 
{
    $content_model = new Content();
    $content = $content_model->getContent($id);
    $response = response()->json($content);

    return $response;
}

and to pull this in my view, i use Jquery $.get method:

$.get('user/getPageContent/'+id, function(response){
    //logic goes here
});

this works well. now if i create the same functionality for a url with no parameter, i do not get a response: i create the route as a get request:

Route::get('user/getAssessmentPage', ['uses'=>'Users\DashboardController@getAssessmentPage', 'as'=>'user.assessmentpage']);

define the function in the controller:

public function getAssessmentPage()
{
    $content= Assessment_Page::all();
    $response = response()->json($content);

    return $response;
}

and try to access it in my view:

$.get('user/getAssessmentPage', function(response){
    console.log(response);
});

but i do not get a response. no response, no error in the console, nothing. so my question is, for url's with no parameters as shown, what would be the way to go to pulling the data?

should also mention i've even given the .load method a try but still no response.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire