I want to make a search function where the results show up without a page refresh. I am new to Ajax and MVC frameworks so I haven't actually tried it before.I don't know where to go about starting this function, especially with Symfony so any help would be appreciated!
This is my search form with a default list of table data's:
<div class="searchsubform">
<form action="{{ path('searchno') }}" method="get">
<input type="text" name="no" placeholder="Search by #" id="searchno"/>
<button type="submit" name="submit">Search</button>
</form>
</div>
<div id="sublist">
<table id="showsub" class="tablesorter">
<thead>
<th>No. ↑↓</th>
<th>Weight ↑↓</th>
<th>Color ↑↓</th>
<th>Dimensions ↑↓</th>
<th>Qty ↑↓</th>
</thead>
{% for entity in entities %}
<tr class="datarow" data-id="{{ entity.subid }}">
<td>{{ entity.no }}</td>
<td>{{ entity.weight }}</td>
<td>{{ entity.color }}</td>
<td>{{ entity.dimensions }}</td>
<td>{{ entity.qty }}</td>
</tr>
{% endfor %}
</table>
</div>
My default index action that displays all the data in the db:
/**
* @return Response
* @Route("/", name="searchhome")
* @Template()
*/
public function indexAction() {
$em = $this->getDoctrine()->getRepository('Bundle:Sub');
$entities = $em->searchSub();
return array('entities' => $entities,);
}
This is the controller I have for the search:
/**
* @Route("/search/", name="searchdano")
* @Template("Bundle:Search:index.html.twig")
*/
public function searchSubByNoAction(Request $request) {
$no = $request->get('no');
$em = $this->getDoctrine()->getRepository('Bundle:Sub');
$entities = $em->searchSubByNo($no);
return $this->render("Bundle:Search:index.html.twig", array(
'entities' => $entities,
));
}
So right now when a user submits a number to search, the page refreshes and displays the rows of results. I need it to just display results without page refresh. I want to target the result display right on the row <tr class="datarow...
Where do I hook the ajax to?