Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/05/2014, 04:17
ecazorla
 
Fecha de Ingreso: abril-2014
Ubicación: Málaga
Mensajes: 13
Antigüedad: 10 años, 1 mes
Puntos: 0
Mi primer AJAX, no funciona!

Hola! Estoy siguiendo una guía de Ajax, he hecho mi primer script como decía la guía pero al hacer submit no sucede nada, le he dado mil vueltas y no veo el fallo.. os dejo los scripts:

display.htm:
Código:
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<frameset rows="100%,0" frameborder="0">
	<frame name="displayFrame" src="display2.htm" noresize="noresize">
    <frame name="hiddenFrame" src="about:blank" noresize="noresize">
</frameset>
<body>
<div id="divCustomerInfo"></div>
</body>
</html>
display2.hym:
Código:
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
	function requestCustomerInfo(){
		var sId = document.getElementById("txtCustomerId").value;
		top.frames["hiddenFrame"].location = "getCustomerdata.php?id=" + sId;
	}
	function displayCustomerInfo(sText){
		var divCustomerInfo = document.getElementById("divCustomerInfo");
		divCustomerInfo.innerHTML = sText;
	}
</script>
</head>
<body>
<p>Enter customer ID number:</p>
<p>Customer id: <input type="text" id="txtCustomerId" value=""/></p>
<p><input type="button" value="Get customer Info" onClick="requestCustomerInfo()"/></p>
</body>
</html>
getCustomerdata.php:
Código:
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
window.onload = function(){
	var divInfoToReturn = document.getElementById("divInfoToReturn");
	top.frames["displayFrame"].displayCustomerInfo(divInfoToReturn.innerHTML);
}
</script>
<title>Untitled Document</title>
<?php
include("start.php");
$sID = $_GET["id"];
$sInfo = "";
$squery = "SELECT * FROM Customers WHERE CustomerId=".$sID;
if($oResult = mysql_query($sQuery) and mysql_num_rows($oResult) > 0){
	$aValues = mysql_fetch_array($oResult,MYSQL_ASSOC);
	$sInfo = $avalues["Name"]."<br/>".$aValues["Address"]."<br/>";
} else
{
	$sInfo = "Customer with ID $sID no existe";
}
?>
</head>

<body>
	<div id="divInfoToReturn"><?php echo $sInfo; ?></div>
</body>
</html>
Un saludo y gracias!