rayrayrugby Posted October 23, 2014 Share Posted October 23, 2014 Hi, I want to run every 10 seconds a php code wich executes a js script in BO. This php code is a part of one of my .tpl div. I know I have to do this using AJAX but I don't really know how to use AJAX in Ps . Could somebody help me please ? Link to comment Share on other sites More sharing options...
vekia Posted October 23, 2014 Share Posted October 23, 2014 you can use hook: backofficefooter and add js file there with script to run ajax call to your php file are you able to code it itself? (especially js function to call php file) ? 1 Link to comment Share on other sites More sharing options...
rayrayrugby Posted October 24, 2014 Author Share Posted October 24, 2014 (edited) Thank you for your reply @vekia, I'm gonna try this, I think I have to call my php file using this in the head of my .tpl : <script type="text/javascript"> $.ajax({ url: 'my_file.php', success: function (data) { alert('content of the executed page: ' + data); }, error: function (xhr, status, error) { if (xhr.status > 0) alert('got error: ' + status); } }); </script> If I understand it, this will execute inside my div 'my_file.php' which contains this : <?php //some sql requests if (condition) { echo ' here is the js which must be executed in BO '; } ?> And I think I have to add a setinterval() in the script which run the AJAX call to make it runs every 10 seconds. Could you please tell me if it is the good way ? Thanks ! Edited October 24, 2014 by rayrayrugby (see edit history) Link to comment Share on other sites More sharing options...
rayrayrugby Posted October 24, 2014 Author Share Posted October 24, 2014 I did it like that : <script type="text/javascript"> function getXMLHttp() { var xmlHttp try { //Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch(e) { //Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert("Your browser does not support AJAX!") return false; } } } return xmlHttp; } function MakeRequest() { var xmlHttp = getXMLHttp(); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { HandleResponse(xhr.responseText); } } xmlHttp.open("GET", "/prestashop/modules/script/my_script.php", true); xmlHttp.send(null); } function HandleResponse(response) { document.getElementById('#scr').innerHTML = response; /*response contains the script I want to run in BO */ } </script> The problem now is that the script is not executed in the div '#scr'. What am I doing wrong ? 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