Passing variables from PHP to JS works in Windows but not in Linux

0

Good afternoon! I have a web application using Php on the server side, and JS on the client. The JS application sends a request to the php via ajax, the php raises an .ini and returns that value. This in Windows is working perfectly. The problem comes to Linux, a server with Centos7, in which I have no way (I have not found so far) to receive the information. Copy-pasteo the pieces of code where the fault occurs:

<?php
if(isset($_POST["refresco"])):
  $properties = parse_ini_file("properties.ini");
  $refresh = $properties["refresco"];
  echo $refresh;

Ese es el codigo en Php. El llamado JS es:

$(document).ready(function(){

            setEventQuery();
            setEventQueryFalse()
            $.ajax({
                url:   'consultaC1.php',                //Esta libreria
                data:  "refresco", //Con este parametro
        type:  'post',          //Con este tipo de transmision de dato
                success: function(response){
                    var refresh = response * 1000;
                    console.log(refresh);
                    actualizarActualTime(refresh);
                }
            }
    );
});

The updateActualTime (refresh) function contains a setInterval () with delay in refresh, as the success returns "", * 1000 throws me a 0, and I end with a super-accelerated loop ...

The .ini contains a line like this: soda = 20

And it is located in the same directory as the .php file

I can not find the problem, which is what could be happening in Linux. If someone could help me ... Thank you very much!

    
asked by Christian Barcelo 09.11.2016 в 20:32
source

1 answer

0

I see several things you should do:

  • In the $ .ajax where you use data: "refresco" I recommend sending a value as a 1 for example, something like data: "refresco=1" .

  • In the $ .ajax options, add the dataType:"json" parameter as well. For example:

  • $.ajax({
      url:"consultaC1.php",
      type:"POST",
      data:"refresco=1",
      dataType:"json",
      success:function(respuesta){
        var refresh = respuesta.refresh;//valor devuelto en php
        console.log(refresh);
        actualizarActualTime(refresh);
      }
    });
    
  • In the php when you print the value echo $refresh; you must change it by:

    echo json_encode(array('refresh'=>$refresh));

  • This is to print an array encoded to JSON where the $ refresh variable is the value of the 'refresh' field so that it can receive it in the ajax as response.refresh.

        
    answered by 10.11.2016 / 20:24
    source