Advertisement
Yanazaki

ajax.js

Sep 2nd, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var map;
  2. var idInfoBoxAberto;
  3. var infoBox = [];
  4. var markers = [];
  5.  
  6. function CriaRequest() {
  7.      try{
  8.          request = new XMLHttpRequest();        
  9.      }catch (IEAtual){
  10.          
  11.          try{
  12.              request = new ActiveXObject("Msxml2.XMLHTTP");      
  13.          }catch(IEAntigo){
  14.          
  15.              try{
  16.                  request = new ActiveXObject("Microsoft.XMLHTTP");          
  17.              }catch(falha){
  18.                  request = false;
  19.              }
  20.          }
  21.      }
  22.      
  23.      if (!request)
  24.          alert("Seu Navegador não suporta Ajax!");
  25.      else
  26.          return request;
  27.  }
  28.  
  29.  /**
  30.   * Função para enviar os dados
  31.   */
  32. window.onload = getDados;
  33.  function getDados(callback) {
  34.      
  35.      // Declaração de Variáveis
  36.    
  37.     // var cep   = document.getElementById("cep").value;
  38.    
  39.      var raio = $('input[name="raio"]:checked').val()
  40.         if(raio == null || raio == undefined)
  41.         {
  42.             var raio = 10;
  43.         }
  44.    
  45.    
  46.      var result = document.getElementById("Resultado");
  47.      var xmlreq = CriaRequest();
  48.  
  49.     if (navigator.geolocation) {
  50.             navigator.geolocation.getCurrentPosition(showPosition);
  51.         } else {
  52.             x.innerHTML = "Seu navegador nao suporte Geolocalização.";
  53.         }
  54.     function showPosition(position) {
  55.         var lat = position.coords.latitude;
  56.         var lng = position.coords.longitude;
  57.  
  58.         lat = lat.toFixed(6);
  59.         lng = lng.toFixed(6);
  60.      
  61.      
  62.      // Iniciar uma requisição
  63.      xmlreq.open("GET", "criando.php?raio=" + raio + "&lat=" + lat + "&lng=" + lng, true);
  64.      
  65.      // Atribui uma função para ser executada sempre que houver uma mudança de ado
  66.      xmlreq.onreadystatechange = function(){
  67.          
  68.          // Verifica se foi concluído com sucesso e a conexão fechada (readyState=4)
  69.          if (xmlreq.readyState == 4) {
  70.              
  71.              // Verifica se o arquivo foi encontrado com sucesso
  72.              if (xmlreq.status == 200) {
  73.                  result.innerHTML = xmlreq.responseText;
  74.                  callback(true);
  75.              }else{
  76.                  result.innerHTML = "Erro: " + xmlreq.statusText;
  77.              }
  78.          }
  79.      };
  80.      xmlreq.send(null);
  81.  }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement