4

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?

2
  • Bsically, you're asking for introductory code or a tutorial. This isn't really the place to ask for this. Commented Nov 24, 2013 at 21:47
  • @Mark What is introductory (also with respect to all other SO's questions) in his/her question, can you explain me? Commented Jul 27, 2016 at 10:29

1 Answer 1

11

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Suresh Kumar Amrani your answer helped me a lot ,have a good day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.