abdfahim
Well-known member
I declared a route with
I have a dropdown in the page where a visitor can select a name, say ABC, and it reloads the page
So, that works fine so far.
Now the question is, can I achieve the same without reloading the whole page, e.g., through an Ajax call? I.e., when a visitor chooses a name from the dropdown, it calls the above class through Ajax, return the data to the portal page, and loads the new data in a predefined DIV?
Thanks,
Controller = Fahim\TestAddon:MyTestPage
and Route prefix = portal-a
, where the class looks like below
PHP:
class MyTestPage extends \XF\Pub\Controller\AbstractController
{
public function actionIndex()
{
$params = $this->filter([
'name' => 'str'
]);
$db = \XF::db();
$results = $db->fetchAllKeyed("SELECT * FROM xf_fahim_test
WHERE `uname` = '".$params['name']."'";
$viewParams = [
'data' => $results,
'params' => $params
];
return $this->view('Fahim\TestAddon:View', 'fahim_portal_a', $viewParams);
}
}
I have a dropdown in the page where a visitor can select a name, say ABC, and it reloads the page
http://example.com/portal-a?name=ABC
which fetches correct data for the user ABC using the above controller.So, that works fine so far.
Now the question is, can I achieve the same without reloading the whole page, e.g., through an Ajax call? I.e., when a visitor chooses a name from the dropdown, it calls the above class through Ajax, return the data to the portal page, and loads the new data in a predefined DIV?
Thanks,