Ver Mensaje Individual
  #9 (permalink)  
Antiguo 28/12/2013, 18:57
mluis12
 
Fecha de Ingreso: noviembre-2013
Mensajes: 7
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: evitar recargar pagina en PHP

hola de nuevo espero no molestar, solo un favor, he visto un tutorial y he probado lo siguiente pero no me hace nada, y lo tengo como en el tutorial, te agradeceria si le pudieras echar un vistazo. muchas gracias.

<?php
include ("conectar.php");
session_start();?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript">
function CreateXmLHttp(){
if (window.XMLHttpRequest){
XmlHttp=new XMLHttpRequest();
} else if (window.ActiveXobject){
XmlHttp= new ActiveXobject("Microsoft.XMLHttp");
}
}
</script>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<link rel="stylesheet" href="tienda.css"/>
<title>Documento sin título</title>

</head>

<body id="body">


<?php


$consulta=mysql_query("SELECT * FROM productos"); //selecciona todos los productos de la tabla.

while($filas=mysql_fetch_array($consulta))
{

$id= $filas['id'];
$imagen= $filas['imagen'];
$nombre=$filas['nombre'];
$descripcion=$filas['descripcion'];
$precio=$filas['precio'];
$existencias=$filas['existencias'];
$fecha=$filas['fecha'];

?>

<table id="tabla" width="225" border="0">

<tr>
<td id="imagen"><img src="<?php echo $imagen; ?>" width="200px" height="175px" /> </td>
</tr>
<tr align="left">
<td id="titulo" width="225" ><?php echo $nombre ?></td>
</tr>
<tr>
<td id="descripcion" width="225" ><?php echo $descripcion ?></td>
</tr>
<tr>
<td id="precio" width="225"><?php echo $precio?>€
<form action="" method="post" name="comprar">
<input name="id_txt" type="hidden" value="<?php echo $id ?>" id="id_txt"/>
<input name="imagen" type="hidden" value="<?php echo $imagen ?>" id="imagen"/>
<input name="titulo" type="hidden" value="<?php echo $nombre ?>" id="titulo"/>
<input name="descripcion" type="hidden" value="<?php echo $descripcion ?>" id="descripcion"/>
<input name="precio" type="hidden" value="<?php echo $precio ?>" id="precio"/>
<input type="button" value="Comprar" id="comprar" onclick="comprar()"/>

</form>


</td>
</tr>


<?php }?>
</table>



</body>

<script type="text/javascript">
<!--document.getElementById("id_txt").focus();-->

function comprar(){
var titulo= document.getElementById("titulo").value;


CreateXmLHttp();
xmlHttp.onreadystatechange = procesardatos;
xmlHttp.open("POST","procesa.php");
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlHttp.send("titulo="+titulo);
}

function procesardatos(){
if(xmlHttp.readystate==4 && xmlHttp.status==200){
alert(xmlHttp.responseText);
}
}
</script>
</html>