elge
elge

Reputation: 3

date search from date picker cannot pass to the controller

This is my code it prints date but not the date from the date picker search it just output today's date not the date search in the date picker:

Here is my input field:

<input type='text' readonly id='search_fromdate' class="datepicker" placeholder='From date'>
<input type='text' readonly id='search_todate' class="datepicker " placeholder='To date'>
<input type='button' id="btn_search" value="Search">

Ajax:

var dataTable = $('#emp-table').DataTable({
  'ajax': {
     'url':url,
       'data': function(data){
          var from_date = $('#search_fromdate').val();
          var to_date = $('#search_todate').val();
          data.searchByFromdate = from_date;
          data.searchByTodate = to_date;
     }
  },

and this is my controller:

public function qTime(Request $request){
    $from_date = '';
    $end_date =  '';
    $from = Carbon::parse($request->searchByFromdate)->toDateString();
    $to = Carbon::parse($request->searchByTodate)->toDateString();

Upvotes: 0

Views: 98

Answers (1)

phaberest
phaberest

Reputation: 3220

You are not returning the object in your data (check the docs https://api.jquery.com/jquery.ajax/)

Something like this should do the trick

var dataTable = $('#emp-table').DataTable({
 'ajax': {
   'url':url,
   'data': function(data){
      return {
        searchByFromdate: $('#search_fromdate').val(),
        searchByTodate: $('#search_todate').val(),
      }
   }
 },

Upvotes: 1

Related Questions