Advertisement
Guest User

Untitled

a guest
Jan 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. [
  2. {
  3. "estado":"Ceará",
  4. "cidade":"Fortaleza",
  5. "nome_revendedor":"Zélia",
  6. "telefone":"85 9999999",
  7. "email":"teste@teste.com.br"
  8. },
  9. {
  10. "estado":"São Paulo",
  11. "cidade":"Carjai",
  12. "nome_revendedor":"Zezé",
  13. "telefone":"85 9999999",
  14. "email":"teste@teste.com.br"
  15. }
  16. ]
  17.  
  18. $('.estado').click(function(e) {
  19. e.preventDefault();
  20. var estado = $(this).attr('xlink:href');
  21. $.ajax({
  22. url: 'servo.php',
  23. type: "POST",
  24. dataType: "json",
  25. data: { estado: estado }
  26. })
  27. .done(function(data) {
  28. $.each(data, function(i, obj) {
  29. $("#titulo").html("Revedendor: " + JSON.stringify(obj.revendedor));
  30. })
  31.  
  32.  
  33. });
  34. return false;
  35. });
  36.  
  37. <?php
  38. if (is_ajax()) {
  39.  
  40. if (isset($_POST["estado"]) && !empty($_POST["estado"])) { //Checks if action value exists
  41. $key_estado = $_POST["estado"];
  42. buscar($key_estado);
  43. }
  44. }
  45.  
  46. //Function to check if the request is an AJAX request
  47. function is_ajax()
  48. {
  49. return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
  50. }
  51.  
  52. function buscar($key_estado)
  53. {
  54.  
  55. $return_arr = array();
  56. $date = 'revendedor';
  57.  
  58. $arr = array(
  59. "estado" => "Ceará",
  60. "cidade" => "Fortaleza",
  61. "nome_revendedor" => "Zélia",
  62. "telefone" => "85 999999",
  63. "email" => "teste@teste.com.br"
  64. );
  65.  
  66. $gg = array(
  67. "estado" => "São Paulo",
  68. "cidade" => "Carjai",
  69. "nome_revendedor" => "Zélia",
  70. "telefone" => "85 999999",
  71. "email" => "teste@teste.com.br"
  72. );
  73.  
  74. $return_arr[$date][] = $gg;
  75. $return_arr[$date][] = $arr;
  76.  
  77. echo json_encode(array(
  78. "revendedor" => $return_arr
  79. ));
  80. }
  81. ?>
  82.  
  83. Estado:
  84. Cidade:
  85. Revendedor:
  86. Telefone:
  87. Email:
  88.  
  89.  
  90. Estado:
  91. Cidade:
  92. Revendedor:
  93. Telefone:
  94. Email:
  95.  
  96. Estado:
  97. Cidade:
  98. Revendedor:
  99. Telefone:
  100. Email:
  101.  
  102. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement