Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/07/2012, 11:35
Avatar de mager3
mager3
 
Fecha de Ingreso: junio-2012
Ubicación: Medellin
Mensajes: 318
Antigüedad: 11 años, 10 meses
Puntos: 4
Exclamación problema paso de variables de Ajax a php

Buenos dias, soy nuevo en ajax, desde internet vi un tutorial para crear listas dependientes donde el usuario selecciona un departamento y de acuerdo a ello carga una lista con los municipios de dicho departamento... PERO NO logro que carguen los municipios, no se si estoy omitiendo algun caracter o algo....

Codigo de convocatoria.php


Cita:
<?php
include ("conexion.php");
include ("calendario/calendario.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registro Hoja de vida</title>
<script language="JavaScript" src="calendario/javascripts.js"></script>
<link rel="STYLESHEET" type="text/css" href="calendario/estilo.css">
<style type="text/css">
<!--
.Estilo1 {
color: #FF3300;
font-weight: bold;
font-size: 12pt;
}
.Estilo2 {
font-size: 12pt;
color: #FF0000;
font-weight: bold;
}
.Estilo3 {
font-size: 12px;
color: #FF0000;
font-weight: bold;
font-style: italic;
}
.Estilo4 {
font-size: 12pt;
font-weight: bold;
font-style: italic;
color: #FF0000;
}
.Estilo5 {
color: #FF0000;
font-weight: bold;
}
-->
</style>
</head>

<script>
//Hacer que funcione con varios navegadores
function requerir(){
try{
req=new XMLHttpRequest();
}catch(err1){
try{
req=new ActiveXObject("Microsoft.XMLHTTP");
}catch(err2){
try{
req=new ActiveXObject("Msxml2.XMLHTTP");
}catch(err3){
req= false;
}
}
}
return req;
}

var peticion=requerir();

function llamarAjaxGETpro(){
var aleatorio=parseInt(Math.random()*999999999);
valor=document.getElementById("txtdepartamento").v alue;
var url="municipios.php?valor="+valor+"&r="+aleatorio;
peticion.open("GET",url,true);
peticion.onreadystatechange =respuestaAjaxpro;
peticion.setRequestHeader('Content-Type','aplication/x-www-form-urlencoded');
peticion.send(null);
}

function respuestaAjaxpro(){

if(peticion.readyState==4){
if (peticion.status==200){
document.getElementById("txtmunicipio").innerHTML= peticion.responseText;
}else{
alert("ha ocurrido un error"+peticion.statusText);
}
}
}
</script>

<?php
$estado=mysql_query("select * from estado_civil");
?>
<body>
<div align="center" class="Estilo2">
<p>CREAR HOJA DE VIDA</p>
<p>&nbsp;</p>
</div>
<form enctype="application/x-www-form-urlencoded" id="fcalen" name="fcalen" method="post" action="">
<table width="647" border="1">
<tr>
<td colspan="2"><div align="center"><span class="Estilo1">Información personal</span></div></td>
</tr>
<tr>
<td colspan="2"><div align="center" class="Estilo1"></div></td>
</tr>
<tr>
<td width="271">Nombre :</td>
<td width="360"><label>
<input name="txtnombre" type="text" id="txtnombre" size="60" />
</label></td>
</tr>
<tr>
<td>Apellidos :</td>
<td><input name="txtnombre2" type="text" id="txtnombre2" size="60" /></td>
</tr>
<tr>
<td>Cedula cuidadania :</td>
<td><input name="txtnombre3" type="text" id="txtnombre3" size="30" /></td>
</tr>
<tr>
<td>Lugar de Nacimiento :</td>
<td><label>
<div id="txtdepartamento" style="width:150; float:left">
<select name="txtdepartamento" id="txtdepartamento" onchange="llamarAjaxGETpro()">
<option>Seleccione depart.</option>
<?php
$re=mysql_query("select * from departamentos");
while($f=mysql_fetch_array($re)){
echo'<option value="'.$f['id_dep'].'">'.$f['descrip_dep'].'</option>';
}
?>
</select>
</div>
<div id="txtmunicipio" style="width:150; float:left">
<select disabled="disable">
<option> Seleccione municipio</option>
</select>
</div>
</label></td>
</tr>
<tr>
<td>fecha de Nacimiento :</td>
<td> <?php
escribe_formulario_fecha_vacio("fecha1","fcalen"); // Cargo el Calendario en el formulario
?> </td>
</tr>
<tr>
<td>Dirección :</td>
<td><input name="txtnombre5" type="text" id="txtnombre5" size="60" /></td>
</tr>
<tr>
<td>Estado civil :</td>
<td><label>
<select name="list_estado" id="list_estado">
<?php
while ($f=mysql_fetch_array($estado)) // Con este arreglo lleno la lista /Menu con los valores de la tabla tipo_usuario
{
echo'<option value='.$f[id_estado].'>'.$f[descrip_estado].'</option>';
}
?>
</select>
</label></td>
</tr>
<tr>
<td>Teléfonos :</td>
<td><input name="txtnombre6" type="text" id="txtnombre6" size="60" /></td>
</tr>
<tr>
<td>Correo Electrónico:</td>
<td><input name="txtnombre7" type="text" id="txtnombre7" size="60" /></td>
</tr>
<tr>
<td><p>Cuenta Skype :</p></td>
<td><input name="txtnombre8" type="text" id="txtnombre8" size="60" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><p class="Estilo3">PERFIL PROFESIONAL (Experiencia en años, actividades concretar realizadas, área o sector de desempeño)</p></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><p align="center" class="Estilo4">ESTUDIOS REALIZADOS</p></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><p class="Estilo5">SECUNDARIA</p></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Institución :</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Programa :</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Duración :</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
<p>&nbsp;</p>
</body>
</html>
y este es el codigo de municipios.php

Código PHP:
<?php
include "conexion.php";
$valor=$_GET['valor'];
//echo $valor;
$re=mysql_query("select * from municipios where id_muni='$valor' ");
echo
'<select id="txtmunicipio" >';
echo
'<option >Seleccione Municipio</option>';
while(
$f=mysql_fetch_array($re)){
 echo
'<option value="'.$f['id_muni'].'">'.$f['descrip_muni'].'</option>';
  }
  echo
'</select>';
 
?>
Me cargan sin problemas los departamentos pero no los municipios, no se si hay algun problema con la variabel 'valor' o que puede ser?