2
I need to get the values of each key inside one loop. The values are in "Blocks":
[  
   {  
      "estado":"Ceará",
      "cidade":"Fortaleza",
      "nome_revendedor":"Zélia",
      "telefone":"85 9999999",
      "email":"[email protected]"
   },
   {  
      "estado":"São Paulo",
      "cidade":"Carjai",
      "nome_revendedor":"Zezé",
      "telefone":"85 9999999",
      "email":"[email protected]"
   }
]
What I already have is basically a SVG map that has links. These links have a class calling for .state. The idea is that by clicking on the status bring your respective information:
 $('.estado').click(function(e) {
     e.preventDefault();
     var estado = $(this).attr('xlink:href');
     $.ajax({
             url: 'servo.php',
             type: "POST",
             dataType: "json",
             data: { estado: estado }
         })
         .done(function(data) {    
             $.each(data, function(i, obj) {
                 $("#titulo").html("Revedendor: " + JSON.stringify(obj.revendedor));    
             }) 
         });
     return false;
 });
I can get the information through a request and for testing purposes I created two array and converted to json, mas o objetivo é criar um loop através de uma consulta SQL e alimentar a variável $return_arr[$date][]:
<?php
if (is_ajax()) {
    if (isset($_POST["estado"]) && !empty($_POST["estado"])) { //Checks if action value exists
        $key_estado = $_POST["estado"];
        buscar($key_estado);
    }
}
//Function to check if the request is an AJAX request
function is_ajax()
{
    return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
}
function buscar($key_estado)
{
    $return_arr = array();
    $date       = 'revendedor';
    $arr        = array(
        "estado" => "Ceará",
        "cidade" => "Fortaleza",
        "nome_revendedor" => "Zélia",
        "telefone" => "85 999999",
        "email" => "[email protected]"
    );
    $gg = array(
        "estado" => "São Paulo",
        "cidade" => "Carjai",
        "nome_revendedor" => "Zélia",
        "telefone" => "85 999999",
        "email" => "[email protected]"
    );
    $return_arr[$date][] = $gg;
    $return_arr[$date][] = $arr;
    echo json_encode(array(
        "revendedor" => $return_arr
    ));
}
?>
Example:
Estado: 
Cidade:
Revendedor:
Telefone: 
Email: 
Estado: 
Cidade:
Revendedor:
Telefone: 
Email: 
Estado: 
Cidade:
Revendedor:
Telefone: 
Email: 
...
						
Perfect. Solved.
– Lollipop