Error recover json on php side

Asked

Viewed 51 times

2

Well, I’m sending a json to php but I can’t recover

$.ajax({
    type: "POST",
    url: "sys/salvar_servidor",
    datType: 'json',
    data: JSON.stringify(dados),
    success: function( data ){
        document.write(data);
    }
});

And in PHP

<?php 

$dados = $_REQUEST['dados'];

$obj = json_decode($dados);

echo  $obj->nome; 

?>

The problem is that PHP gives me an error stating that the data variable is not defined.

  • It worked! Thank you. Could you tell me what was going on?

1 answer

2


Set the name of the field that will send json, the current way is it sent without name, do

data: {'dados': JSON.stringify(dados)},
  • 1

    Thank you! It worked.

  • @Some, missed to define the name(data) in your ajax, before was sent without name.

  • Got it. It’s all working now =) See you later

Browser other questions tagged

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