title: How to use Ajax in Laravel on a button?
body: <p>I have an ajax table that I want to filter the results of all active courses using ajax. </p>
  
  <p>Here is what I've tried - view </p>
  
  <p>Button - Filter active records</p>
  
  <pre><code>&lt;a href="{{ route('admin.courses.index',['$active_records'=&gt;'active']) }}" style="margin-left:10px;" class="btn btn-success"&gt;
              Active &lt;span class="badge badge-light"&gt;{{$course_count_active}}&lt;/span&gt;
            &lt;span class="sr-only"&gt;total courses&lt;/span&gt;&lt;/a&gt;
  </code></pre>
  
  <p>Table that I need to filter the results when the button is clicked </p>
  
  <pre><code>&lt;p&gt;
          &lt;ul class="list-inline"&gt;
              &lt;li&gt;&lt;a href="{{ route('admin.courses.index') }}" style="{{ request('show_deleted') == 1 ? '' : 'font-weight: 700' }}"&gt;@lang('global.app_all')&lt;/a&gt;&lt;/li&gt; |
              &lt;li&gt;&lt;a href="{{ route('admin.courses.index') }}?show_deleted=1" style="{{ request('show_deleted') == 1 ? 'font-weight: 700' : '' }}"&gt;@lang('global.app_trash')&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/p&gt;
  
  
      &lt;div class="panel panel-default"&gt;
          &lt;div class="panel-heading"&gt;
              @lang('global.app_list')
          &lt;/div&gt;
  
          &lt;div class="panel-body table-responsive"&gt;
              &lt;table class="table table-bordered table-striped ajaxTable @can('course_delete') @if ( request('show_deleted') != 1 ) dt-select @endif @endcan"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
                          @can('course_delete')
                              @if ( request('show_deleted') != 1 )&lt;th style="text-align:center;"&gt;&lt;input type="checkbox" id="select-all" /&gt;&lt;/th&gt;@endif
                          @endcan
  
  
                          &lt;th&gt;@lang('global.courses.fields.title')&lt;/th&gt;
                          &lt;th&gt;@lang('global.courses.fields.safety-topic')&lt;/th&gt;
                          &lt;th&gt;@lang('global.courses.fields.course-image')&lt;/th&gt;
                          &lt;th&gt;@lang('global.courses.fields.start-date')&lt;/th&gt;
                          &lt;th&gt;@lang('global.courses.fields.due-date')&lt;/th&gt;
                          &lt;th&gt;@lang('global.courses.fields.status')&lt;/th&gt;
  
                          @if( request('show_deleted') == 1 )
                          &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                          @else
                          &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                          @endif
                      &lt;/tr&gt;
                  &lt;/thead&gt;
              &lt;/table&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  @stop
  </code></pre>
  
  <p>Here is the ajax script </p>
  
  <pre><code>@section('javascript')
      &lt;script&gt;
          @can('course_delete')
              @if ( request('show_deleted') != 1 ) window.route_mass_crud_entries_destroy = '{{ route('admin.courses.mass_destroy') }}'; @endif
          @endcan
          $(document).ready(function () {
              window.dtDefaultOptions.ajax = '{!! route('admin.courses.index') !!}?show_deleted={{ request('show_deleted') }}';
              window.dtDefaultOptions.columns = [@can('course_delete')
                  @if ( request('show_deleted') != 1 )
                      {data: 'massDelete', name: 'id', searchable: false, sortable: false},
                  @endif
                  @endcan
  
                  {data: 'title', name: 'title'},
                  {data: 'safety_topic.topic', name: 'safety_topic.topic'},
                  {data: 'course_image', name: 'course_image'},
                  {data: 'start_date', name: 'start_date'},
                  {data: 'due_date', name: 'due_date'},
                  {data: 'status', name: 'status', searchable:true},
                  {data: 'actions', name: 'actions', searchable: false, sortable: false}
              ];
              processAjaxTables();
          });
      &lt;/script&gt;
  @endsection
  </code></pre>
  
  <p>I'm currently the button is refreshes the page, however the results are not being filtered.</p>