I have a template with specific data, that has filter options for displaying articles. I want that when a user clicks on a filter option, another template will be loaded inside this template with AJAX that will display the articles based on the selected filter option. I've been searching on 'net but all I found was ambiguous and most was about returning a simple response and not a twig. Please help me with this issue.
Does anyone have a simple example on how to do that in Symfony 2?
You can do like this this is your html form where ajax call
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
function SearchForm(){
var brand=$('#brand').val();
$.ajax({
type:'POST',
url: $('#url').text(),
data: {brand: brand,},
success: function(response) {
$('#all_data_search').html(response);
}});
return false;
}
</script>
<div id="all_data_search"></div>
<inputtype="button" onClick="SearchForm()">
and your controller you have to call this method
public function productSeachResultAction(Request $request){
$data = $request->request->all();
// What you want to do ///
return $this->render('AdminBundle:Product:searchResult.html.twig',$productResult);
}
Create another template for result searchResult.html.twig Work you want to do her
<div>
a,b,c,
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With