4
How would it be possible to send the following Json to Php without losing the "tabLinhas", Where do you have an array!? The original Json consists of a single line, I put this way here only to improve the visualization:
{"csTipoPagamento":"20",
"csClassificacao":"14",
"csContrato":"41",
"csFornecedor":"Nome_do_Fornecedor",
"csNotaFiscal":"2316549-9",
"csValorNotaFiscal":"2413.08",
"csCnpj":"Uma_numeração_de_CNPJ",
"csEmissao":"28/06/2015",
"csVencimento":"28/07/2015",
"csMunicipio":"275",
"csDtpInicial":"01/06/2015",
"csDtpFinal":"30/06/2015",
"csRefPgto":"9",
"csIngressSpd":"29/06/2015",
"csData":"02/07/2015",
"csLiId":"O_Id",
"csMedicao":"A_Medição",
"csPedido":"Numeração_do_pedido",
"csDtpRecebNota":"30/06/2015",
"csDescServico":"Uma_Descrição",
"csObservacoes":"Uma_Observação",
"tabLinhas":[
["33","12","102","1","12","2413.08","569659","201.09"],
["33","12","102","1","12","2413.08","569659","201.09"]
]}
I’ve tried it this way:
In Javascript:
var str_json = JSON.stringify(myObject);
request= new XMLHttpRequest();
request.open("POST", "recebeJson.php", true);
request.setRequestHeader("Content-type", "application/json");
request.send(str_json);
alert(str_json); //Exibe o json perfeitamente na janela de alerta
In Php, getting Json via POST:
var_dump($_POST);
echo '<br><br>Erro(s): '.json_last_error();
Php Post var_dump output:
array(16) {
["csTipoPagamento"]=> string(1) "1"
["csClassificacao"]=> string(2) "15"
["csContrato"]=> string(1) "6"
["csNotaFiscal"]=> string(9) "3126549-2"
["csEmissao"]=> string(10) "29/06/2015"
["csVencimento"]=> string(10) "29/07/2015"
["csMunicipio"]=> string(3) "309"
["csCecoAprov"]=> string(6) "CJ9700"
["csDtpInicial"]=> string(10) "01/06/2015"
["csDtpFinal"]=> string(10) "30/06/2015"
["csRefPgto"]=> string(1) "9"
["csIngressSpd"]=> string(10) "28/06/2015"
["csPedido"]=> string(15) "Pedido qualquer"
["csDtpRecebNota"]=> string(10) "29/06/2015"
["csDescServico"]=> string(13) "Uma Descrição"
["csObservacoes"]=> string(14) "Uma Observação"
}
Output from json_last_error():
Erro(s): 0
After the POST, besides already arriving as an array, I’m missing some of this.
And what happens that way?
– Maicon Carraro
The way I did, the whole final part, the tabLinhas, is lost between sending in Js and receiving in Php.
– Victoralm
Why do you say it’s lost? How are you using this JSON in PHP? put the pf code
– Sergio