Ton Gok
Ton Gok

Reputation: 152

Daterange Filter in Symfony using fosjsrouting Bundle

I'm very new to ajax requests. I'm trying to make a date range filter to show posts between two dates, for that i'm using this Calendar.

This is the Calendar Input:

<input type="text" name="daterange"/>

And in Js i use this Code:

$(document).ready(function() {
    $('input[name="daterange"]').daterangepicker(
        {
            "alwaysShowCalendars": true,
            "cancelClass": "btn-primary",
        });
$('.applyBtn').click(function(){
    startDate = $('input[name="daterange"]').data('daterangepicker').startDate.format('DD.MM.YYYY');
    endDate = $('input[name="daterange"]').data('daterangepicker').endDate.format('DD.MM.YYYY');
    var url = Routing.generate('calender-posts-filter', { start: startDate, end: endDate });
    $.ajax({
        url: url,
        type: 'GET',
    });
    console.log(url);
});

});

And this is my function in Symfony

public function filterAction($start, $end){

    $posts = $this->getDoctrine()->getRepository(Post::class)->getFilteredPosts($start, $end);



    return $this->render('app/posts-date-filtered.html.twig', ['posts' => $posts]);
}

When i Choice two dates and i press the apply Btn i get the right Date generated from jsRouting and i got it posted in console but then no thing else happening. How to to refresh the page with the new URL if the Ajax request not working here.

Upvotes: 1

Views: 196

Answers (0)

Related Questions