Hola gente, tengo el siguiente problema. Tengo una pagina con dos div, en uno de ellos tengo un menu y en el otro, muestro con ajax la pagina correspondiente al linck que clickee en el menu. El problema es que nose como hacer para que luego de borrar un producto redireccione automaticamente a la pagina anterior en el div contenedor y no el index.
Pego el codigo.
Este es el index donde tengo el menu y el div contenedor:
Código HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="css.css" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<style media="all" type="text/css">@import "css.css";</style>
<script type="text/javascript">
function getPages(divid,url)
{
if(divid !="" && url != "")
{
var ob= AjaxObject();
var unixTimeStamp= fetch_unix_timestamp();
var nocacheurl = url+ "?t=" + unixTimeStamp;
ob.onreadystatechange=function()
{
if(ob.readyState==4)
{
if(ob.status == 200)
{
if(ob.responseText != null)
{
document.getElementById(divid).innerHTML=ob.responseText;
}else
{
alert('There was an error: no data was received');
}
}else
{
alert('Ajax error:' + ob.statusText);
}
}
}
ob.open("GET",nocacheurl,true);
ob.send(null);
}else{
alert('Se te a olvidado colocar el id del DIV o el URL en el href del achor tag, en el evento de onClick ');
}
}
function fetch_unix_timestamp()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}
function AjaxObject()
{
var xmlHttp;
try{
return xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
return xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
return xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Sorry AJAX is not supported by your browser.");
return false;
}
}
}
}
</script>
</head>
<body>
<div class="principal" style="background-color: #e0e0e0;">
<div id="menu" class="menu">
<ul>
<li><a id="current" href="stock.php" onClick="getPages('response',this); return false" >HOME</a>
</li>
<li><a href="borrar.php" onClick="getPages('response',this); return false" >Borrar</a>
</li>
</ul>
</div>
<table cellpadding="0" cellspacing="0" style="margin-top: 20px" >
<tr>
<td>
<div id="response" style="height: 500px">
<?php include ("stock.php"); ?>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
Esta es la pagina borrar en la cual selecciono los productos que deseo borrar
Código HTML:
<?php
include_once 'lib.php';
$conexion= mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $conexion);
$result = mysql_query("SELECT id_stock, codigo, descrip, pre_min, pre_may, disponibles FROM stock where activo = '1'", $conexion);
?>
<form name='borrar' method='post' action='borrar_prod.php'>
<table id="etiquetas" border='1'>
<tr style="background-color: #ffff99">
<th>ID</th>
<th>Codigo</th>
<th style='width: 500px'>Descrip</th>
<th>Prec.Min</th>
<th>Prec.May</th>
<th>Disponibles</th>
<th></th>
</tr>
<?php
$i=0;
while($row = mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $row['id_stock'] ?></td>
<td><?php echo $row['codigo'] ?></td>
<td style='width: 500px'><?php echo $row['descrip'] ?></td>
<td align=right><?php echo "$"; echo $row['pre_min'] ?></td>
<td align=right><?php echo "$"; echo $row['pre_may'] ?></td>
<td align=center><?php echo $row['disponibles'] ?></td>
<td><input name='seleccion[]' type='checkbox' value=<?php echo $row['id_stock']?>></td>
</tr>
<?php
$i++;
}
?>
</table>
<br>
<input type='submit' name='submit' value='enviar'>
</form>
Y esta es la pagina donde borro y como ven en la parte inferior tengo un header que apunta al index y como explique arriba quiero que vuelva a cargar la pagina borrar (osea la anterior) denuevo en el contenedor
Código PHP:
<?php
require_once 'lib.php';
foreach ($_POST['seleccion'] as $id){
echo $id."<br>";
}
$conexion= mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $conexion);
// Generamos una lista de los ID's (campo value= ..) que tenemos en nuestro array.
$lista=implode(',',$_POST['seleccion']);
// Y lo aplicamos al SQL correspondiente y ejecutamos la consulta.
mysql_query("UPDATE stock set activo = 0 WHERE id_stock IN(".$lista.")");
header("Location: index.html");
?>