Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "estado":"Ceará",
- "cidade":"Fortaleza",
- "nome_revendedor":"Zélia",
- "telefone":"85 9999999",
- "email":"teste@teste.com.br"
- },
- {
- "estado":"São Paulo",
- "cidade":"Carjai",
- "nome_revendedor":"Zezé",
- "telefone":"85 9999999",
- "email":"teste@teste.com.br"
- }
- ]
- $('.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;
- });
- <?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" => "teste@teste.com.br"
- );
- $gg = array(
- "estado" => "São Paulo",
- "cidade" => "Carjai",
- "nome_revendedor" => "Zélia",
- "telefone" => "85 999999",
- "email" => "teste@teste.com.br"
- );
- $return_arr[$date][] = $gg;
- $return_arr[$date][] = $arr;
- echo json_encode(array(
- "revendedor" => $return_arr
- ));
- }
- ?>
- Estado:
- Cidade:
- Revendedor:
- Telefone:
- Email:
- Estado:
- Cidade:
- Revendedor:
- Telefone:
- Email:
- Estado:
- Cidade:
- Revendedor:
- Telefone:
- Email:
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement