Empty request data from ajax in laravel 5.4 -


i want change value based on selected year , week ajax.

this ajax function:

function changebekeken() {         var year = $("#jaar-nr").val();         var week = $("#week-nr").val();         $.ajax({             headers: {                 'x-csrf-token': $('meta[name="csrf-token"]').attr('content')             },             url: "/planning/viewed",             type: "post",             data: {                 year_nr: year,                 week_nr: week             },             datatype: "json",             success: function(data) {                 alert(data);             }         });     }     $(document).ready(function(){         $("#week-nr").change(function(){             changebekeken();         });         $("#jaar-nr").change(function(){             changebekeken();         });     }); 

this route:

route::post('/planning/viewed', 'planningcontroller@viewed'); 

the data send controller function:

public function viewed(request $request) {     $check = db::table('planning_files')         ->where([             ['user_id', auth::user()->id],             ['created_year', $request->input('year_nr')],             ['week', $request->input('week_nr')],         ])         ->select('seen')         ->first();     if($check) {         return json_encode($check, json_pretty_print);     } else {         return json_encode(false);     } } 

however when use $request->all(); request empty. function return false. pretty exact same function works on page, can't seem 1 working.

i have tried adding information ajax function, content type , data type, none seem work.

any tips?

edit 1

these namespaces , classes use in controller:

namespace app\http\controllers; use illuminate\http\request; use db; use auth; use storage; 

edit 2

when copy function page works properly. has content on page use ajax function on. conflict token. try resolve , post answer others if might have same problem in future.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -