prak Posted February 21, 2017 Share Posted February 21, 2017 Hello, I am trying to call a php function on clicking a button in my module. I have added the ajax-call.php in the root folder of my module. Here is my code : jquery to call the function $('.target').unbind('click').click(function(){ $.ajax({ url: '{$base_dir}modules/customizeproducts/ajax-call.php', type: 'get', data:'ajax=true', success: function(data) { console.log(data); } }); return false; }); ajax-call.php <? php require_once(dirname(__FILE__).'../../../config/config.inc.php'); require_once(dirname(__FILE__).'../../../init.php'); public function call(){ return "called from ajax-call.php"; } if ($_GET['ajax']){ echo function call(); } ?> console.log(data) returns the whole file, how can I get the value returned by the call() function? Link to comment Share on other sites More sharing options...
Gabriel Perez Posted February 21, 2017 Share Posted February 21, 2017 (edited) Hi ! try this : <?php require_once(dirname(__FILE__).'../../../config/config.inc.php'); require_once(dirname(__FILE__).'../../../init.php'); function call(){ return "called from ajax-call.php"; } if (Tools::isSubmit('ajax')){ echo call(); } Note that you have a white space in php aperture (< ? php). Perhaps you should replace the echo for die too. Edited February 21, 2017 by Gabriel Perez (see edit history) 1 Link to comment Share on other sites More sharing options...
prak Posted February 21, 2017 Author Share Posted February 21, 2017 Thanks for the replyl! I changed my php code as you said and now I am getting a 500 internal server error Link to comment Share on other sites More sharing options...
bellini13 Posted February 21, 2017 Share Posted February 21, 2017 Thanks for the replyl! I changed my php code as you said and now I am getting a 500 internal server error show us your new code. the issue is likely the space on line 1 <? php also, checked your php error log for the actual error behind the 500 1 Link to comment Share on other sites More sharing options...
Gabriel Perez Posted February 21, 2017 Share Posted February 21, 2017 (edited) Change the debug to know the error. file /confi/defines.inc.php : /* Debug only */ if (!defined('_PS_MODE_DEV_')) { define('_PS_MODE_DEV_', true); } Edit : sorry, wrong language xD Edited February 21, 2017 by Gabriel Perez (see edit history) Link to comment Share on other sites More sharing options...
prak Posted February 21, 2017 Author Share Posted February 21, 2017 show us your new code. the issue is likely the space on line 1 <? php also, checked your php error log for the actual error behind the 500 It seems that the space was the issue, here is my code now: ajax-call.php <?php require_once(dirname(__FILE__).'../../../config/config.inc.php'); require_once(dirname(__FILE__).'../../../init.php'); public function call(){ return "called from ajax-call.php"; } if (Tools::isSubmit('ajax')){ echo call(); } I checked the log and the reason for 500 error is "server reached pm.max_children setting (5), consider raising it", I found that the value of pm.max_children was set to 5 in www.conf, what value should I give it? Link to comment Share on other sites More sharing options...
prak Posted February 21, 2017 Author Share Posted February 21, 2017 Cambia el debug para saber cual es el error 500 : Archivo /confi/defines.inc.php : /* Debug only */ if (!defined('_PS_MODE_DEV_')) { define('_PS_MODE_DEV_', true); } I had already set _PS_MODE_DEV_ to true, I think I just have to raise the pm.max_children Link to comment Share on other sites More sharing options...
prak Posted February 21, 2017 Author Share Posted February 21, 2017 I have changed these values in my www.conf file, php.max_children to 500, php.max_requests to 10000, pm.min_spare_servers to 20 and pm.max_spare_servers to 100 and restarted php7.0-fpm. Now I get the same error message in the console but nothing in the log. error message in the console: 'GET http://localhost/modules/customizeproducts/ajax-call.php?ajax=true 500 (Internal Server Error) XHR finished loading: GET "http://localhost/modules/customizeproducts/ajax-call.php?ajax=true".' Link to comment Share on other sites More sharing options...
prak Posted February 21, 2017 Author Share Posted February 21, 2017 commenting out everything and just putting echo works fine, so I guess it's not a php error Link to comment Share on other sites More sharing options...
prak Posted February 21, 2017 Author Share Posted February 21, 2017 Well, I tried this and it is working <?php require_once(dirname(__FILE__).'../../../config/config.inc.php'); require_once(dirname(__FILE__).'../../../init.php'); function call(){ echo "called from ajax-call.php"; } if($_GET['ajax']){ call(); } ?> Thank you both very much for your replies 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