Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Se me recarga la página sola

Estas en el tema de Se me recarga la página sola en el foro de Frameworks JS en Foros del Web. El caso es que tengo una página con tres divs, en el primero cargo un mapa de Google Maps con una serie de marcadores, y ...
  #1 (permalink)  
Antiguo 26/03/2009, 09:55
 
Fecha de Ingreso: octubre-2007
Mensajes: 4
Antigüedad: 16 años, 6 meses
Puntos: 0
Se me recarga la página sola

El caso es que tengo una página con tres divs, en el primero cargo un mapa de Google Maps con una serie de marcadores, y en el segundo genero un formulario desde un archivo XML con AJAX. Entonces quiero que cuando el usuario pulse enviar en el formulario, la respuesta del servidor se cargue en el tercer div.

En IE llego a ver la tabla, pero al cabo de unos segundos la página se recarga y desaparece el contenido de este tercer div, mientras que en Firefox directamente se recarga sin mostrar nada.

¿Qué puede fallar?

Código HTML:
<body>
<div id="map" style="width:830px; height:550px; float:left"></div>
<div id="form" style="float:left; margin-left:10px">
<form name="observation"  method="post">
<select name="offering" id="offering" onchange="return offeringOnChange()">
		<option>Select offering...</option>
<?php
$xml = simplexml_load_file('capabilities.xml');
$result = $xml->xpath("/ObservationOfferingList/ObservationOffering/Offering | /ObservationOfferingList/ObservationOffering/@id");
for ($i=0;$i<count($result);$i+=2) {
	$e=$i+1;
	echo("<option value='$result[$i]'>$result[$e]</option>");
}
?>
	</select>
<!-- Aquí van más select y los input -->
<input name="Submit" type="submit"  onclick="return cargarContenido()" />
</form>
</div>
<div id="contenedor" style="float:left"></div>
</body> 
Código:
function cargarContenido(){
	var contenedor = document.getElementById('contenedor');
	CreateXmlHttpObj();
	XmlHttpObj.open("POST", "form.php", true);
	XmlHttpObj.onreadystatechange=function() {
		if (XmlHttpObj.readyState==4) {
			if (XmlHttpObj.status == 200) {
			contenedor.innerHTML = XmlHttpObj.responseText;
			}
	 	}
	}
	XmlHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	XmlHttpObj.send('');
}
Un saludo.

Última edición por Pablovp; 30/03/2009 a las 03:16
  #2 (permalink)  
Antiguo 26/03/2009, 09:58
 
Fecha de Ingreso: octubre-2007
Mensajes: 4
Antigüedad: 16 años, 6 meses
Puntos: 0
Respuesta: Se me recarga la página sola

La función que carga el mapa es esta, que estoy seguro de que por alguna razón que desconozco es la que recarga la página entera.

Código:
<script type="text/javascript">
    //<![CDATA[
	if (GBrowserIsCompatible()) {
		// A function to create the marker and set up the event window
		function createMarker(point,name,html) {
        	var marker = new GMarker(point);
        	GEvent.addListener(marker, "click", function() {
          		marker.openInfoWindowHtml(html);
        	});
			return marker;
		}
		// Create the map
		var map = new GMap2(document.getElementById("map"));
		map.setMapType(G_HYBRID_MAP);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(10,10), 2);
		// Read the data from marker.xml
		GDownloadUrl("marker.xml", function(doc) {
			var xmlDoc = GXml.parse(doc);
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");			  
			for (var i = 0; i < markers.length; i++) {
				// Obtain the attribues of each marker
				var lat = parseFloat(markers[i].getAttribute("lat"));
				var lng = parseFloat(markers[i].getAttribute("lng"));
				var point = new GLatLng(lat,lng);
				var label = markers[i].getAttribute("label");
				var html = '<h3>' + label + '<\/h3>' + markers[i].getAttribute("html");
				// Create the marker
				var marker = createMarker(point,label,html);
				map.addOverlay(marker);
			}
		})
    } else {
		alert("Sorry, the Google Maps API is not compatible with this browser");
    }
    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    //]]>
</script>
  #3 (permalink)  
Antiguo 30/03/2009, 03:14
 
Fecha de Ingreso: octubre-2007
Mensajes: 4
Antigüedad: 16 años, 6 meses
Puntos: 0
Respuesta: Se me recarga la página sola

He quitado el mapa y sigue recargandose, así que no es el mapa el que da problemas. Tiene que ser algo en el formulario, ya que se recarga para volver a llenar el primer select.
Un saludo.

PD: He actualizado el código arriba.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:15.