Reply from PHP Excel in JSON

Asked

Viewed 99 times

1

I’m trying to get an answer to whether the Phpexcel already downloaded, to then proceed with my algorithm.

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

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

But it doesn’t 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);
   }
});
  • Instead of echo, try a die(json_encode(array("teste" => 1))); and let me know what happened.

  • but I take out the Exit you have at the end?

  • die will stop the process and return the content that was placed inside. You can leave everything as it is and just make the change;

  • he delayed and returned undefined

  • Well, let’s go to the next and last test,, $.ajax({
 type : 'post',
 url : 'services/'+url,
 datatype: 'json',
 data : {
 data : competencia
 },
 success: function (data) {
 if(data.teste === 1)
 alert('baixou');
 else
 alert('nao baixou: '+data.teste);
 }
});

  • Nothing. Now neither Alert shows more. But it was worth the intention to help

  • var form = $('<form action="services/'+url+'" method="post" >'+&#xA; '<input type="hidden" value="'+competencia+'" name="data" />'+&#xA; '</form>');&#xA; $('body').append(form);&#xA; form.submit() if I put this command works, but I have no way to know the return in jquery

  • I would like you to update the page only after downloading

Show 3 more comments

1 answer

0

Parse 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);
   }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.