0

I have a date picker and I put a jquery listener to it on change:

$('#viewmonth').datepicker({language: 'ja', autoclose: true, minViewMode: 'months', format: $('#month_format').text(),}) .change(function() { let date = $(this).datepicker("getDate"); let month = date.getMonth() + 1; date = date.getFullYear() + '-' + month; $.ajax({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, type:'GET', url:'/head/sale/h_2_501/changeMonth', data: {'viewmonth': date} }); }); 

When the date is changed, it redirects to changeMonth function:

public function changeMonth() { $viewmonth = date("Y-m-d", strtotime(Request::input('viewmonth'))); $viewmonth = mb_convert_kana($viewmonth, 'a'); error_log($viewmonth); $filter = $this->pageInfo['filter']; $filter['viewmonth'] = $viewmonth; $this->updateFilterData($filter); return redirect()->route('head.sale.h_2_501'); } 

Inside this function, I am changing the date of the query I use to display some data. The problem is after redirecting to the index route inside changeMonth, the results display doesn't change but the query changed. How do I also update the data displayed?

1
  • You're calling changeMonth() via AJAX so the response will be returned to your $.ajax() caller (via the success callback or done method). You don't appear to be attempting to handle the response at all Commented Oct 14, 2018 at 4:19

1 Answer 1

1

First remove return redirect()->route('head.sale.h_2_501'); from changeMonth() function.

Then add it to the AJAX success call.

$.ajax({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, type:'GET', url:'/head/sale/h_2_501/changeMonth', data: {'viewmonth': date}, success: function (response) { // this is the redirect after your changeMonth() function succeed. window.location = '{{ route('head.sale.h_2_501') }}' } }); 
Sign up to request clarification or add additional context in comments.

3 Comments

It doesn't call the route() correctly here, I'm getting a different route
This is the url it redirects to after calling that: 127.0.0.1:8000/head/sale/…
isn't this a .blade.php file? If it's not, you can't use {{ }} these. then you have to use the exact url, example window.location = 'http://127.0.0.1:8000/head/sale/whatever_your_other_parts'.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.