How to send parameters by ajax using datatable in laravel?

0

JavaScript code:

function activar_tabla_listasedes() {
    var codigo = 105147000738;
     $('#tablesedes').DataTable({
         processing: true,
         serverSide: true,
         pageLength: 5,
         language: {
                  "url": '{!! asset('/plugins/datatables/latino.json') !!}'
                   },
         ajax:{
           url : '{{ route('datatable.sedes') }}',
           type: "POST",
           data: {"estable": codigo}
         },
         columns: [
             { data: 'codigo_sede', name: 'codigo_sede' },
             { data: 'nombre_sede', name: 'nombre_sede' },
             { data: 'direccion', name: 'direccion' },
             { data: 'telefono', name: 'telefono' },
             { data: 'nombre_departamento', name: 'nombre_departamento' },
             { data: 'nombre_municipio', name: 'nombre_municipio' },
             { data: 'estado_sede', name: 'estado_sede' }

         ]

     });
  }

route:

Route::get('/vistas_due_listasedes', 'ConsultaBasicaDueController@vistas_due_listasedes')->name('datatable.sedes');

driver:

function vistas_due_listasedes(Request $request)
  {
    $estable = $request->get('estable');
    $sedes = HistoricoSede::select(['codigo_sede','nombre_sede','direccion','telefono','nombre_departamento','nombre_municipio','estado_sede'])->where('codigo_establecimiento',$estable);
    return Datatables::of($sedes)->make(true);
  }

The error that stops me is:

{message: "", exception: "Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException",…}
exception
:
"Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException"
file
:
"C:\xampp\htdocs\siega\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php"
line
:
255
message
:
""
trace
:
[,…]
    
asked by Andrés Cantillo 14.06.2018 в 16:22
source

1 answer

1

Your route is GET type and you send the request of ajax with POST type, that's why it tells you MethodNotAllowedHttpException. Change any of the 2 to the other and it will work for you

    
answered by 14.06.2018 / 16:56
source