Jump to content

run a js script in BO


rayrayrugby

Recommended Posts

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 by rayrayrugby (see edit history)
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...