AJAX - Variable

 
Vista:
sin imagen de perfil

Variable

Publicado por Jose (1 intervención) el 02/09/2013 21:13:28
Buen dia!!

Lo que pasa es que necesito mandar unas variables por ajax a php por metodo GET y lo que pasa es que tengo una que esta dentro de un while php y la variable es un id y siempre me saca el ultimo registro y el codigo ajax lo tengo dentro del while php y no me funciona, la variable se llama id_pregunta ; ahi les dejo el ejercicio!!
Gracias

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
while ($pre=mysql_fetch_array($pr)){
 
	echo "<form method='post' id='foo' name='responder' action='plataforma_virtual.php?plataforma=responder_opciones'>";
 
		$pregunta=$pre['pregunta'];
		$id_pregunta=$pre['id_pregunta'];
 
		echo "<input type='radio' name='respuesta' value='$num_opcion'>".$opcion;
		echo "<br>";
		echo "<br>";
		//echo $num_opcion;
 
		}
		echo "<br>";
 
		echo $id_pregunta;
		?>
		<script>
			function loadXMLDoc()
			{
			var xmlhttp;
			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("myDiv").innerHTML=xmlhttp.responseText;
				}
				}
			xmlhttp.open("GET","responder_opciones.php?id_taller=<?php echo $id_taller; ?>&id_unidad=<?php echo $id_unidad; ?>&id_pregunta=<?php echo $id_pregunta; ?>",true);
			xmlhttp.send();
			}
		</script>
 
		<?php
		echo "<input type='button' value='Guardar pregunta' onclick='loadXMLDoc()' class='btn btn-defalut'>";
		echo "<br>";
 
		echo "<input type='hidden' name='total' value='$total'>";
	echo "</form>";
}
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 Dionisio

Variable

Publicado por Dionisio (2 intervenciones) el 05/02/2014 15:13:38
Verifica algunas cosas el WHILE

no te entiendo bien lo que tratas de explicar pero creo saber cual es el error

el codigo ajax hace mencion a un ID, por tanto si tienes este codico dentro de un bucle el ID se repetira

document.getElementById("myDiv")


lo que yo haria es que crearia un contador que incremente al final del bucle y concatenaria esto al nombre del ID

document.getElementById("myDiv"+count)

de esta manera generas document.getElementById("myDiv1"), document.getElementById("myDiv2"), etc
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