Wednesday, March 29, 2017

Trying to do a post request to laravel ajax jquery function based on html declared value

im tryign to retrieve the id field from a html class, i get it sucessfully,

html blade gives a href="javascript:void(0)" class="mainsection-button" mainsection-id="IDVALUE" >

and ajax sends it to the controller as post, what i want is the controller to pass the received parameter to run the base function of the controller with the passed parameter, but it gives me the next error in browser console :

POST http://localhost:81/Laravel/public/mainsection-page 500 (Internal Server Error)

here is the blade js

$(document).ready(function(){
            $(document).on('click', '.mainsection-button', function(){
                var mainsection_id = $(this).attr('mainsection-id');
                console.log(mainsection_id);
                $.ajax({
                    // laravel route access
                    url: '',
                    type: 'post',
                    data: {input_mainsection: mainsection_id},
                    success:function(response){

                        console.log(response);


                    }


                });

mainsection_controller.php ( here i try to pass values to the base function of the controller mainfunction()}

public function getSectionPage(Request $request)
{

    return response()->json($request->input_mainsection);


mainfunction($request->get('input_mainsection'));

}

routes

Route::group(['middleware' => 'auth'], function(){

Route::post('mainsection-page', ['as' => 'mainsection:page', 'uses' =>   'section_controller@getSectionPage']);
});

Any idea why im getting the 500 error at console? Thank you!



via Molon

Advertisement