prak Posted March 6, 2017 Share Posted March 6, 2017 Hello, I have made an admin controller for my module and I wish to send some data to it using ajax. Is this possible? If it is possible, how can I do that? Help would be greatly appreciated. Link to comment Share on other sites More sharing options...
rocky Posted March 7, 2017 Share Posted March 7, 2017 Just add a function starting with process to your controller. For example: public function processRegenerate() { echo 'Regenerating...'; die; } Then simply add &action=regenerate to the end of your controller's URL to call the function. Change regenerate to any string that describes what your function is doing. 1 Link to comment Share on other sites More sharing options...
prak Posted March 7, 2017 Author Share Posted March 7, 2017 Hello and thanks for the reply Rocky, I did not know that. Is there a similar way to send a value for a variable and access it using $_GET method in the controller and then display it in the view? Link to comment Share on other sites More sharing options...
rocky Posted March 7, 2017 Share Posted March 7, 2017 You can add more query strings to the URL and then access the data within the function. For example, if the query string is &action=regenerate&type=images: public function processRegenerate() { $type = Tools::getValue('type'); echo $type; die; } This will save "images" to the $type variable and then print it out. You can then read it from result function of the AJAX call. 2 Link to comment Share on other sites More sharing options...
prak Posted March 7, 2017 Author Share Posted March 7, 2017 Thanks a lot rocky!! Link to comment Share on other sites More sharing options...
Estian Posted October 21, 2020 Share Posted October 21, 2020 (edited) Good day - 3 years later and I can not for the life of me get an ajax call to work. PrestaShop: 1.7.6.5 Module: CustomModule Ajax URL:https://domain/module/CustomModule/CustomModuleOrderManagerController?action=productStockIssue&id_product=###&id_order=###&ajax=true class CustomModuleOrderManagerController extends ModuleAdminController { public function processProductStockIssue() { $this->ajaxDie( Tools::jsonEncode( ['error' => 'This is a test 2.'] ) ); } } Am I missing something? It just responds with 404 not found with everything that I try. Edited October 21, 2020 by Estian Incomplete (see edit history) Link to comment Share on other sites More sharing options...
Estian Posted October 21, 2020 Share Posted October 21, 2020 Turns out I had to register a "tab" (the controller name) for the controller in "installTab()" during module installation. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now