I have built a website using php and the zend framework. In one of the pages I have a zend form and a table. The user can fill in the form, click the search button(page refresh occurs) and then get the corresponding results in the table.
What I am trying to do is to implement the same functionality using Ajax so the page won't have to refresh or ask for re-submission when reloaded.
From my controller I pass the data I want to display to view.phtml. When the page first opens all the data from database gets displayed in the table. Somehow after the user clicks search :
- the ajax post data should be retrieved in the controller
- compared to the rest of the data to see if there are any matches
-
return the data matched
public function searchAction(): ViewModel { $persons = $this->personsService->getAllPersons(); $form = $this->personsForm;
if ($this->getRequest()->isPost()) { $formData = $this->params()->fromPost(); $form->setData($formData); if ($form->isValid()) { $validFilteredData = $form->getData(); $persons = $this->personsService->getPersonsAfterSearch($validFilteredData); } } return new ViewModel([ 'persons' => $persons, 'form' => $form, ]); }
I would like any suggestions on how to implement ajax since I am a beginner in web development and I don't experience working with ajax.
Thanks in advance.