I'm working in a project and I'm stuck here, I don't know why I can't get the list from my database\
Here is my JAVASCRIPT
$(document).ready(function(){
$.ajax({
url:'datos.php?accion=ac',
success:function(datos){
for(x = 0;x<datos.length;x++){
//$("#PAIS").append("<option value='"+datos[x].id_pais+"'>"+datos[x].pais+"</option>");
$("#PAIS").append(new Option( datos[x].pais, datos[x].id_pais));
}
}
})
$("#PAIS").change(function(){
//var felix=$('#PAIS option:selected').val();
//alert(felix);
$.ajax({
url:'datos.php?accion=ad',
alert('hola22');
success:function(datos1){
console.log("hola");
for(x = 0;x<=datos1.length;x++){
//$("#PAIS").append("<option value='"+datos[x].id_pais+"'>"+datos[x].pais+"</option>");
$("#REGION").append(new Option( datos1[x].region, datos1[x].id_region));
}
}
})
});
})
And my functions.php:
<?php
$server="localhost";
$usr="root";
$passwd="";
$data="combo";
$db=mysqli_connect($server,$usr,$passwd,$data) or die ("Error en la conexion1");
$Accion = $_GET['accion'];
if($Accion=="ac"){
header('Content-Type: application/json');
$paises = array();
$Consulta = mysqli_query($db,"SELECT * FROM paises")or die ("Error en la conexion7");
while($Fila=mysqli_fetch_assoc($Consulta)){
$paises[] = $Fila;
}
echo json_encode($paises);
}
if($Accion=="ad"){
header('Content-Type: application/json');
$regiones = array();
$Consulta1 = mysqli_query($db,"SELECT * FROM regiones WHERE id_pais=4");//.$_REQUEST['id_pais']);
while($Fila=mysqli_fetch_assoc($Consulta1)){
$regiones[] = $Fila;
//echo json_encode($Fila);
}
echo json_encode($regiones);
}
?>
Well, my problem it's that I really don't know how the first really works :D, but when I'm calling url:datos.php=ad this block doesn't work :/