Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/06/2012, 10:40
Avatar de diegovazgonz
diegovazgonz
 
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 6 meses
Puntos: 11
Error en la ejecucion json

El script extrae el contenido de un input para buscar su direccion en google, luego descarga uno de los valores del json, por ejemplo el campo name
Código Javascript:
Ver original
  1. $(document).ready(function() {
  2.    
  3.     $("#busprin").keypress(function(e) {
  4.     if(e.keyCode == 13) {
  5.        
  6.         $.ajax({
  7.                 async:  true,
  8.                 url:    "http://maps.google.es/maps/geo?output=json&sensor=true&q=" + $("#busprin").val(),
  9.                 dataType:"json",
  10.                 success: function(data){
  11.                      var json = data;
  12.                      alert(json.name);
  13.                     },
  14.                 error:function(data){
  15.                      alert('Error');
  16.                     }
  17.                 });
  18.     }});
  19.      
  20. });


Código json:
Ver original
  1. {
  2.   "name": "ourense",
  3.   "Status": {
  4.     "code": 200,
  5.     "request": "geocode"
  6.   },
  7.   "Placemark": [ {
  8.     "id": "p1",
  9.     "address": "Ourense, España",
  10.     "AddressDetails": {
  11.    "Accuracy" : 4,
  12.    "Country" : {
  13.       "AdministrativeArea" : {
  14.          "AdministrativeAreaName" : "Galicia",
  15.          "SubAdministrativeArea" : {
  16.             "Locality" : {
  17.                "LocalityName" : "Ourense"
  18.             },
  19.             "SubAdministrativeAreaName" : "Orense"
  20.          }
  21.       },
  22.       "CountryName" : "España",
  23.       "CountryNameCode" : "ES"
  24.    }
  25. },
  26.     "ExtendedData": {
  27.       "LatLonBox": {
  28.         "north": 42.3983214,
  29.         "south": 42.2881793,
  30.         "east": -7.8059585,
  31.         "west": -8.0037342
  32.       }
  33.     },
  34.     "Point": {
  35.       "coordinates": [ -7.8646408, 42.3400086, 0 ]
  36.     }
  37.   } ]
  38. }
__________________
El mejor vino Ribeiro http://www.pedeperdiz.com