en que me equivoco?
Publicado por Iván Calderón (3 intervenciones) el 13/02/2009 16:33:42
Saludos y gracias, estoy empezando en esto de ajax y estoy barado tengo el siguiente archivo .htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
window.onload=iniciartodo;
var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;
var peticion;
function iniciartodo()
{
peticion=iniciar_xhr();
if(peticion)
{
cadena="xtabla='sistamunicipios'";
peticion.onreadystatechange = mostrarresultado;
peticion.open('POST', 'http://localhost/Educacion/php/cargarcombo.php', true);
peticion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
peticion.send(cadena);
}
}
function iniciar_xhr()
{
if(window.XMLHttpRequest){
return new XMLHttpRequest();
}
else if(window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function mostrarresultado()
{
var documentoxml;
var seleccionado;
if(peticion.readyState == READY_STATE_COMPLETE)
{
if (peticion.status == 200)
{
documentoxml=peticion.responseXML;
document.getElementById("res").innerHTML=peticion.responseText;
alert(documentoxml.getElementsByTagName("municipios")[0].firstChild.nodeValue);
}
}
}
</script>
</head>
<body>
</body>
</html>
Y el siguiente archivo .PHP
<?php
header('Content-Type: text/txt; charset=ISO-8859-1');
$conexion=mysql_connect("localhost","root");
mysql_select_db("Educacion",$conexion);
$instruccion="select * from sistamunicipios";
$resultado=mysql_query($instruccion,$conexion);
$num_lineas=mysql_num_rows($resultado);
if($num_lineas>0)
{
echo "<municipios>";
while($objeto_fila = mysql_fetch_object($resultado))
{
echo "<municipio>";
echo "<codigo>" . $objeto_fila->CodiMuni . "</codigo>" ;
echo "<nombre>" . $objeto_fila->NombMuni . "</nombre>" . "<br>";
echo "</municipio>";
}
echo "</municipios>";
}
?>
Si corro solo el archivo php me imprime los municipios bien pero si corro el archivo .htm no me reconoce lo devuelto por la pagina PHP,es decir, yo espero que la linea:
alert(documentoxml.getElementsByTagName("municipios")[0].firstChild.nodeValue);
me muestre el primer municipio segun lo que e leido pero no me reconoce no aparece nada, pido disculpa si mi pregunta es muy tonta y agradesco mucho toda la colaboración
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
window.onload=iniciartodo;
var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;
var peticion;
function iniciartodo()
{
peticion=iniciar_xhr();
if(peticion)
{
cadena="xtabla='sistamunicipios'";
peticion.onreadystatechange = mostrarresultado;
peticion.open('POST', 'http://localhost/Educacion/php/cargarcombo.php', true);
peticion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
peticion.send(cadena);
}
}
function iniciar_xhr()
{
if(window.XMLHttpRequest){
return new XMLHttpRequest();
}
else if(window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function mostrarresultado()
{
var documentoxml;
var seleccionado;
if(peticion.readyState == READY_STATE_COMPLETE)
{
if (peticion.status == 200)
{
documentoxml=peticion.responseXML;
document.getElementById("res").innerHTML=peticion.responseText;
alert(documentoxml.getElementsByTagName("municipios")[0].firstChild.nodeValue);
}
}
}
</script>
</head>
<body>
</body>
</html>
Y el siguiente archivo .PHP
<?php
header('Content-Type: text/txt; charset=ISO-8859-1');
$conexion=mysql_connect("localhost","root");
mysql_select_db("Educacion",$conexion);
$instruccion="select * from sistamunicipios";
$resultado=mysql_query($instruccion,$conexion);
$num_lineas=mysql_num_rows($resultado);
if($num_lineas>0)
{
echo "<municipios>";
while($objeto_fila = mysql_fetch_object($resultado))
{
echo "<municipio>";
echo "<codigo>" . $objeto_fila->CodiMuni . "</codigo>" ;
echo "<nombre>" . $objeto_fila->NombMuni . "</nombre>" . "<br>";
echo "</municipio>";
}
echo "</municipios>";
}
?>
Si corro solo el archivo php me imprime los municipios bien pero si corro el archivo .htm no me reconoce lo devuelto por la pagina PHP,es decir, yo espero que la linea:
alert(documentoxml.getElementsByTagName("municipios")[0].firstChild.nodeValue);
me muestre el primer municipio segun lo que e leido pero no me reconoce no aparece nada, pido disculpa si mi pregunta es muy tonta y agradesco mucho toda la colaboración
Valora esta pregunta


0