Come fare una richiesta Ajax In un JS Popup?
Domanda
Ho un problema con un AJAX richiesta "speciale". Ho una forma con diverse combo (tag "Select"). Sto caricando gli oggetti per ogni combinazione da un DB MySQL, con una classe appositamente progettata per me. Ogni Combo ha un "+" Button (Per Aprire un pop-up e aggiungere una nuova voce). Quando l'utente "salva" il nuovo valore, la richiesta AJAX dovrebbe funzionare, ma, nulla accadrà. Ah, un altro dettaglio:. Quando il nuovo valore viene salvato nel DB, il pop-up si chiudono automaticamente
Questo è il codice Pop-Up (PHP):
<?php
require ("class\BD.php");
require ("class\combos.php");
require ("xajax/xajax_core/xajax.inc.php");
$Conex = new BD();
if (isset($_POST['GuardarTipoSist']))
{
$Ajax = new xajax();
function cargarTipoSistema()
{
$Combo = new combos();
$Combo->setParams('cobTipo',$Conex);
$Contenido = $Combo->CargarCombo();
$AjaxResponse = new xajaxResponse();
$AjaxResponse->assign("cobTipo","innerHTML",$Contenido);
}
$Ajax->registerFunction("cargarTipoSistema");
$TipoSist = $_POST['txtTipoSist'];
$Query = "INSERT INTO Tipos_Sistemas VALUES(NULL,'$TipoSist')";
$Conex->query($Query);
$Ajax->processRequest();
echo '<script>alert("Guardado Correctamente"); return true; window.close();</script>';
}
?>
E questo è il codice HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Ingresar Tipo Sistema - GESPROGAN</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<style type="text/css">
<!--
.Estilo2 {
font-size: 16px;
color: #827BCC;
}
.Estilo12 {
color: #FFFFFF;
font-size: 10px;
font-weight: bold;
font-style: italic;
}
-->
</style></head>
<script type="text/javascript" language="javascript" src="validaciones.js"></script>
<body>
<table width="390" height="270" border="1">
<tr>
<td bordercolor="#F0F0F0" background="images/dominios tipo sistema.png" width="380" height="264"><p> </p>
<p> </p>
<form name="DomTipoSist" action="dominios_tipo.php" method="POST" onsubmit="return validarIngDatHac(); return true;">
<table width="371" height="166" border="1" align="center">
<tr>
<th width="361" height="160" scope="col"><p class="Estilo2">POR FAVOR INGRESE EL NUEVO TIPO DE SISTEMA </p>
<table width="341" height="68" border="1">
<tr>
<td height="27" colspan="2">
<input id="txtTipoSist" name="txtTipoSist" type="text" size="55"/>
</td>
</tr>
<tr>
<td width="162" height="33">
<div align="center">
<input id="GuardarTipoSist" name="GuardarTipoSist" type="submit" value="GUARDAR"/>
</div>
</td>
<td width="163">
<div align="center">
<input id="Cancelar" name="Cancelar" type="button" value="CANCELAR" onclick="javascript:window.close()"/>
</div>
</td>
</tr>
</table>
<p class="Estilo2"><span class="Estilo12"> - GESPROGAN.. <strong><em>© </em></strong>Todos los Derechos Reservados 2010- -</span></p>
</th>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
L'AJAX richiesta shoud ricaricare il Combo nel "Parent-Form", con tutte le voci della BD (Incluso quello nuovo).
La mia domanda è, posso fare la richiesta AJAX nel Pop-Up? O come posso fare questo?
Grazie in anticipo!
PS: Mi dispiace per il mio inglese, io non sono un "madrelingua".
Soluzione
Esegui la richiesta Ajax nella finestra principale, non nel popup. Così, per esempio, quando si invia il modulo nel popup, fare un window.opener.cargarTipoSistema ();