0
I need to send data via ajax to record, and one of the information is an array, but the array loses positions when I receive it in PHP, I don’t know if there is a size limit for the AJAX object sent, if you had to split the array into several as you would do multiple data uploads in the same ajax request?
var dadosPost = {
'qtdNotas' : notasSelecionadasArray.length,
'transacao': $("#transacao").val(),
'flag_tipo_romaneio' : transacaoSelect.flag_tipo_entrega,
'motorista': $("#motorista").val(),
'veiculo': $("#veiculo").val(),
'placa': veiculoSelect.placa,
'ajudante1': $("#ajudante1").val(),
'ajudante2': $("#ajudante2").val(),
'notas': notasSelecionadasArray
};
if(validateState){
$.ajax({
//url da pagina
url: $("#baseURL").val()+'romaneio/criarRomaneio',
//url: $("#baseURL").val()+'/views/romaneio/tes.php',
//parametros a passar
data: (dadosPost),
//tipo: POST ou GET
//dataType: 'JSON',
type: 'POST',
//cache
cache: false,
beforeSend: function(){
$('.loading').css({display:"block"});
},
The variable notes is an array with several selected notes, to avoid problems I am sending the amount of items contained in the array in JS to compare in PHP but this limits the application, I need to send a larger number of selected notes.
PHP
$notasSelecionadas = ($_POST['notas']);
$qtdNotas = ($_POST['qtdNotas']);
$transacao = $_POST['transacao'];
$motorista = $_POST['motorista'];
$veiculo = $_POST['veiculo'];
$ajudante1 = $_POST['ajudante1'];
$ajudante2 = $_POST['ajudante2'];
$flagTipoRomaneio = $_POST['flag_tipo_romaneio'];
if(count($notasSelecionadas) >= 1){
if(count($notasSelecionadas) == $qtdNotas){
$dets = array();
foreach($notasSelecionadas as $n){
$o_romaneioDet = new RomaneioDetModel();
$o_romaneioDet->setNotaFiscal(DataFilter::numeric($n['no_docto']));
$o_romaneioDet->setCodCliente(DataFilter::cleanString($n['cod_cliente']));
$o_romaneioDet->setNomeCliente(DataFilter::cleanString($n['razao_cliente']));
$o_romaneioDet->setEndCliente(DataFilter::cleanString($n['endereco']));
$o_romaneioDet->setCidadeCliente(DataFilter::cleanString($n['cidade']));
$o_romaneioDet->setBairroCliente(DataFilter::cleanString($n['bairro']));
$o_romaneioDet->setFoneCliente(DataFilter::cleanString($n['fone']));
$o_romaneioDet->setFaturamento($n['faturas']);
$o_romaneioDet->setSerieNotaFiscal(DataFilter::cleanString($n['serie_nfe']));
$o_romaneioDet->setModeloNf(DataFilter::cleanString($n['modelo_nf']));
$o_romaneioDet->setDtEmissaoNf(DataFilter::cleanString($n['dt_emissao_nf']));
array_push($dets, $o_romaneioDet);
tried to use like this:
'notas' : JSON.stringify(notasSelecionadasArray);
– adventistaam
What you’re sending is object is not? array is not {} is [] dai if you’re going to access php by object would be dataPosts->qtdNotas example...
– Anderson Henrique
I’ll put as I do in PHP.
– Bruno C.
it is true what @Andersonhenrique said, if it is already converted into array does only call in php you use
$notasArray = json_decode($_POST['notas']);
– adventistaam
How you are sending the notesSelectionArray?
– adventistaam
I have no problem receiving the values, I am receiving, the problem is that if I send 100 selected notes, in PHP it does not reach 100, depending on the amount of information contained in the notes array, the number of positions sent varies, for example, if I pick up 100 notes with Address Completed or is too much text, arrives only 40 note, if I take notes with no address with less information there arrives 60...
– Bruno C.
This is because the POST has size limit, what you could do is find in json and in php use the Code limit is 16.777.215 characters.
– Anderson Henrique