JSON return for PHP with Ajax

1

I'm trying to pass a JSON (result of a Google Place API) with Ajax to PHP. I think my problem is in PHP when it comes to manipulating the data, it follows a part of the code:

AJAX:

//GRAVA TODO O RETORNO NO BANCO...                
            $.ajax({

                types: 'GET',
                dataType: "json",
                url: 'http://'+VARendereco+'/WB_CADASTRO_USUARIO3/www/busca.php',
                data: "dados="+Dados_json+"&acao=salva_toda_busca_web",
                success: function(data){
                //alert(data[0].status);
                //$('#sub-pagina').html(data);
                //alert(data);
                alert("Gravou_busca2");
                }
            });

PHP:

if($_GET["acao"] == "salva_toda_busca_web"){
    //$matriz = stripslashes($_GET["dados"]);
    $matriz = json_decode($_GET["dados"], true);
    $itens = $matriz['results'];

        //foreach ( $itens as $e ){
    $SQL = "INSERT INTO tb_busca_geral (conteudo_busca, id_usuario, qt_resultados, local, lat, lon)VALUES('".$itens['name']."', 10, 5, '', '', '')";
    $num = mysqli_query($serve, $SQL);
    //echo $itens->name; 
        //} 
}

It writes the record, more blank in this field ... If anyone has any ideas, thank you!

json (Google example, in this format):

    
asked by anonymous 06.02.2016 / 13:11

1 answer

1

I was able to solve it this way:

$matriz = json_decode ( json_encode ($_POST['dados']), true);

I did not really understand why it worked just this way, coding and decoding again, if someone knows how to explain it there ... But it worked perfectly with a foreach, and I took the opportunity to switch to POST that has more resources transferability and is considered more secure ...

Thank you!

    
07.02.2016 / 16:05