php - Display results in twig json -


i have in controller function make search filter.

the search parameter obtained select field of twig template.

the selected option passed controller see results value.

the query result returned in json format.

controller:

public function categoryaction(request $request)     {         $category = $request->request->get('category');          $contentcategory = $em->getrepository('myappbundle:content')->findbycategory($category);          $filtercontent = new jsonresponse();          $filtercontent->setdata([             'categoryresult' => $contentcategory         ]);          return $filtercontent;     } 

twig template:

$('#selectcategory').change(function() {                 var optionselect = $(this).val();                 $.ajax({                     url: '{{path('playlist_category') }}',                      data: '&category='+optionselect,                     type: 'post',                     success: function(filtercontent) {                     },                     error: function(e){                         console.log(e.responsetext);                     }                 });             }); 

how can display result returned in json in function 'success'?

you should change js code following. rather user $.post $.ajax. , don't forget pass json fourth arg.

$('#selectcategory').on('change', function () {     var optionselect = $(this).val();     $.post("{{path('playlist_category') }}", {category: optionselect}, function (res) {         console.log(res);     }, 'json'); }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -