Jonathan Rodz Posted October 9, 2013 Share Posted October 9, 2013 (edited) Hello everyone, I'm getting crazy googling and trying to understand the ajax functionality on modules. I really hope I can find some knowledge to bring some light in, cos it's beeing looooong hours already. Scenario: I create a module on homepage showing some feature product. All great. I'm quering the DB, I got my results, I show them, and all is perfect, but I've been asked to change that "feature list" based on different criteria (diferent queries). I'm thinking on different possibilities: 1.- Reload the hook passing a different parameter (I think I can't reload a module without reloading the page). 2.- Access to the controller from .tpl file (user interaction) on real time to re-display with different values (diferent functions reloading the same tpl with different values... maybe). 3.- Load content straigh with AJAX, ignoring mvc (I'm not fan of that idea, but I didn't achive that solution either because DB access outside the framework). 4.- Create a few different modules and switch them (but if I load all of them at once the page will load really slow, so it has to be ajax somehow). I didn't copy the example cos it's a little bit complex, but I'll be happy to share my code once I know what to share without flooding the topic. Any inspiration it will be appreciated Thanks in advance Edited October 9, 2013 by Jonathan Rodz (see edit history) Link to comment Share on other sites More sharing options...
math_php Posted October 10, 2013 Share Posted October 10, 2013 (edited) Hi Jonathan, If you have a controller for your module, ajax in POST mode have to call your controller. Your controller will not display tpl because you will add 'ajax=true' for example and then your code will only deal with json output for example and not display the controller html part. Ajax calling in POST mode, transmit also Cookies, you will then, in your controller, have access to guest id, country id... Best regards Edited October 10, 2013 by math_php (see edit history) 1 Link to comment Share on other sites More sharing options...
Jonathan Rodz Posted October 11, 2013 Author Share Posted October 11, 2013 Thanks math_php! I read your text carefully, and I'm trying to get the concept. I can follow this concept to go on? http://stackoverflow.com/questions/18501001/prestashop-ajax-call-module I will share the solution once is solved Regards Link to comment Share on other sites More sharing options...
math_php Posted October 11, 2013 Share Posted October 11, 2013 Hi Jonathan, Let type to 'get' for debug and dev time and further if and only if you do not need info from the framework : <script type="text/javascript"> function QuickLook() { $.ajax({ url: '{$base_dir}modules/quicklook/quicklook-ajax.php', type: 'get', On stackoverflow I do not see 'quicklook-ajax.php' ? Is it a real file or do you think prestashop is going to call your method 'ajaxCall' ? Prestashop will not. I think you are really close, but I or you are misunderstanding something 1 Link to comment Share on other sites More sharing options...
Jonathan Rodz Posted October 11, 2013 Author Share Posted October 11, 2013 math_php, I do need info from the framework. I'll focus on what I have and I'll come back later with some quality questions if they are. thanks so far! Link to comment Share on other sites More sharing options...
Jonathan Rodz Posted October 16, 2013 Author Share Posted October 16, 2013 thanks math_php for you indications!! :) at the end all is solved with the bridge file first I call it (bridge file) through AJAX: $.ajax({ type: 'POST', url: baseDir + 'modules/homefeatured/homefeatured-ajax.php', data: 'ajax=true', dataType: 'html', success: function(data) { $('#test').html(data); }}); that's the bridge: <?phpinclude(dirname(__FILE__).'/../../config/config.inc.php');include(dirname(__FILE__).'/../../init.php');include(dirname(__FILE__).'/homefeatured.php');$home = new HomeFeatured();echo $home->ajaxCall();?> and I created on homefeatured.php this ajaxCall function: public function ajaxCall() { global $smarty; //all you wanna process, within the framework } 1 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