I'm working with php, mysql and jquery. Where I create a json with php that brings a single data, and I'll find it with jquery ajax. If I make a console.log to my data variable brought with ajax it shows me the data like this: [{"folio": "456235"}], but when it parses it shows an empty object. I do not know what I may be doing wrong, this is my code js:
function getFolio(){
var action3 = 'buscaFolio';
$.ajax({
type: 'GET',
data: {action: action3,cod_sec: cod_sec,periodo: periodo,nro_oa: nuevo},
url: '../folios.php',
//dataType: 'Json',
success: function (data) {
var parsedData = JSON.parse(data);
console.log(parsedData);
},
error: function () {
console.log('Error al buscar folio');
}
});
Any idea what's going on? thanks
php code Model:
public function getFolio($cod_sec,$nro,$periodo){
$sql = ' SELECT * FROM ventas WHERE codigoseccion='.$cod_sec.' AND nro='.$nro.' AND periodo='.$periodo.' ';
$sqlQuery = new SqlQuery($sql);
$arr = $this->execute($sqlQuery);$ret = Array();
foreach ($arr as $t) {
$f = array(
'folio'=>$t['folio']
);
array_push($ret,$f);
}
return(json_encode($ret));
}
Controller:
$cod_sec = $_GET['cod_sec'];
$nro = $_GET['nro'];
$periodo = $_GET['periodo'];
$objOa3 = new Cargos_controller();
print_r($objOa3->getFolio($cod_sec,$nro,$periodo));