PHP Excel response in JSON

1

I'm trying to get an answer to see if the PHPExcel PHPExcel file already downloaded, and then proceed with my algorithm.

I tried to put in the phpexcel file the following line before the exit;

echo json_encode(array("teste" => 1));

But it does not work. It returns as undefined

$.ajax({
  type : 'post',
  url  : 'services/'+url,
  data : {
     data : competencia
 },
 success: function (data) {
   if(data.teste === 1)
    alert('baixou');
   else
     alert('nao baixou: '+data.teste);
   }
});
    
asked by anonymous 05.06.2017 / 20:45

1 answer

0

Make a parse of the returned data, so you have an object.

$.ajax({
  type : 'post',
  url  : 'services/'+url,
  data : {
     data : competencia
 },
 success: function (data) {
   //Parse do JSON retornado
   var obj = JSON.parse(data);

   if(obj.teste === 1)
    alert('baixou');
   else
     alert('nao baixou: '+data.teste);
   }
});
    
10.04.2018 / 01:53