JQuery - Pasar variables con .load

 
Vista:
sin imagen de perfil

Pasar variables con .load

Publicado por miguel (2 intervenciones) el 01/09/2014 21:18:01
Hola, soy novato en esto de Jquery y estoy peleando para adaptar un codigo a un mapa de google. La cosa es que logro ubicar resultados en un mapa de google y luego quiero que ese link/resultado que se genera me actualice cierta info en un <div> y aqui esta el error, no logro pasar la variable php para que el div me reciba. Si escribo este numero Literalmente digamos, funciona perfecto, no así si intento con una variable. Copio el codigo completo a ver si me dan un amano. Gracias!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//codigo del maps de google
 
    <script src="http://maps.google.com/maps/api/js?sensor=false"
            type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
 
    var customIcons = {
      1: {
        icon: 'images/educacionE.png'
      },
      2: {
        icon: 'images/saludE.png'
      },
      3: {
        icon: 'images/seguridadE.png'
      },
      4: {
        icon: 'images/administracionE.png'
      },
      5: {
        icon: 'images/equipamientoE.png'
      },
      6: {
        icon: 'images/socialE.png'
      },
      7: {
        icon: 'images/cultoE.png'
      },
      8: {
        icon: 'images/planificacionE.png'
      },
      9: {
        icon: 'images/culturaE.png'
      }
    };
 
    function load() {
      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(-28.945669, -57.903442),
        zoom: 7,
        mapTypeId: 'terrain'
      });
      var infoWindow = new google.maps.InfoWindow;
 
// Change this depending on the name of your PHP file
      downloadUrl("phpsqlajax_genxml3e.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("name");
          var address = markers[i].getAttribute("address");
		  var NombreObra = markers[i].getAttribute("NombreObra");
 
		  var IdOb = markers[i].getAttribute("IdObras");  // ESTA ES LA VAR QUE NECESITO LLEVAR AL DIV
 
		  var id = markers[i].getAttribute("id");
          var type = markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
 
          var html = "<table width=260px><tr><td width=90px><img src=images/fotitos/" + id + ".jpg width=90 height=60></td><td width=170px><a href=# onclick='cargar();'>" + name + "</a><br>" + address +"</td></tr></table>";
 
//ESTE ES EL LINK QUE ME LLEVA AL DIV Y QUE MANDA LA VARIABLE
 
          var icon = customIcons[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });
    }
 
    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }
 
    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;
 
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };
 
      request.open('GET', url, true);
      request.send(null);
    }
 
    function doNothing() {}
 
    //]]>
 
function cargar() // ESTA  ES LA FUNCION QUE ENVIA LA VAR
{
     $('#central').load('detalleiteva.php?IdObras=', {IdObras: 750});   // EL NUM DEBERIA SER REEMPLAZADO POR LA VAR.
}
</script>

LES DEJO EL LINK PARA QUE LO VEAN http://www.dpo.gov.ar/mapas/mapadeobrasenejecucion2.php
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 302
Oro
Ha mantenido su posición en JQuery (en relación al último mes)
Gráfica de JQuery

Pasar variables con .load

Publicado por xve (673 intervenciones) el 02/09/2014 07:40:24
Hola Miguel, y porque no la pasas como parámetro a la función? algo como:
1
var html = "<table width=260px><tr><td width=90px><img src=images/fotitos/" + id + ".jpg width=90 height=60></td><td width=170px><a href=# onclick='cargar("+IdOb+");'>" + name + "</a><br>" + address +"</td></tr></table>";

Y en la función lo capturas...
1
function cargar(IdOb)

Coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Pasar variables con .load

Publicado por Miguel (2 intervenciones) el 03/09/2014 13:59:18
Gracias xve !!!!
Era lo que faltaba, de todas formas tuve q agregarle algunos detalles. Al final el codigo quedo así:

el boton que actauliza el div:

1
var html = "<table width=260px><tr><td width=90px><img src=images/fotitos/" + id + ".jpg width=90 height=60></td><td width=170px><a href=# onclick='cargar("+IdOb+");'>" + name + "</a><br>" + address +"</td></tr></table>"; ///GRACIAS XVE

el script que ejecuta:

1
2
3
4
function cargar(IdOb)
{
     $('#central').load('detalleiteva.php', {IdObras: IdOb});
}

el div que recibe:

1
<div id="central">   </div>

el archivo php que se actualiza (detalleiteva.php) recibe el id con

1
$IdObras = $_GET['IdObras'];

Nuevamente Gracias !! Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar