AJAX - valor de option en ajax

 
Vista:
sin imagen de perfil

valor de option en ajax

Publicado por mario (3 intervenciones) el 20/02/2016 07:42:26
buenas, tengo un problema, el problema es que tengo un select y al tener el valor de entero en option value ='1' todo bien pero al tener un value = "ud-11-11" no me envia nada, me podrian ayudar.
solo intento imprimir en la pantalla los datos de la tabla.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<script>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
 
        };
        xmlhttp.open("GET","ajax.php?q="+str,true);
        xmlhttp.send();
    }
}
</script>
 
<?php
 
  error_reporting (E_ALL ^ E_DEPRECATED);
 
$conexion = mysql_connect("localhost", "root", "");
 
if (!$conexion) {
    echo "No pudo conectarse a la BD: " . mysql_error();
    exit;
}
 
if (!mysql_select_db("pres")) {
    echo "No ha sido posible seleccionar la BD: " . mysql_error();
    exit;
}
 
 
$sentancia = "select * from materias";
$query = mysql_query($sentancia,$conexion);
 
 
?>
 
 
<form >
 
<select  name="M" onchange="showUserr(this.value)">
<option value="">Seleccionar:</option>
<?php while($lista = mysql_fetch_array($query)) { ?>
<option value="<?php echo $lista[0] ?>" ><?php echo $lista[0] ?></option>
<?php } ?>
</select>
 
</form>
<div id="txtHint"><b>Informacion </b></div>


otro archivo
ajax.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<style>
table {
    width: 100%;
    border-collapse: collapse;
}
 
table, td, th {
    border: 1px solid black;
    padding: 5px;
}
 
th {text-align: left;}
</style>
</head>
<body>
 
<?php
 
$q = intval($_GET['q']);
 
$con2 = mysqli_connect('localhost','root','');
if (!$con2) {
    die('Could not connect: ' . mysqli_error($con2));
}
 
mysqli_select_db($con2,"prestamo");
 
$sql="SELECT * FROM materias WHERE IDMat = '$q'";
$result = mysqli_query($con2,$sql);
 
echo "<table>
<tr>
<th>Numero de materia</th>
<th>Nombre</th>
</tr>";
while($row2 = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row2[0] . "</td>";
    echo "<td>" . $row2[1] . "</td>";
    echo "</tr>";
}
echo "</table>";
mysqli_close($con2);
?>
</body>
</html>


ayudenme porfavor!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Vainas
Val: 47
Ha mantenido su posición en AJAX (en relación al último mes)
Gráfica de AJAX

valor de option en ajax

Publicado por Vainas (71 intervenciones) el 20/02/2016 21:29:20
Buenas:

Yo solo veo mal esto:

1. No coincide el nombre de la funcion:

1
function showUser(str) {

1
select name="M" onchange="showUserr(this.value)">

2. Pasas el valor a un entero:

1
$q = intval($_GET['q']);

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

valor de option en ajax

Publicado por mario (3 intervenciones) el 20/02/2016 21:32:23
es cierto bro, pero eso si esta bien, solo que tome otra funcion pero en mi onchange="showUser(this.value)", no entiendo porque solo me toma el valor del option int enteros y no otro tipo de caracteres.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

valor de option en ajax

Publicado por mario (3 intervenciones) el 20/02/2016 21:59:15
es cierto bro el problema era ese:

$q = intval($_GET['q']); pasaba puro entero muchas gracias;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar