如何在 JS 弹出窗口中发出 AJAX 请求?

发布于 2024-09-27 19:32:38 字数 3881 浏览 4 评论 0原文

我遇到“特殊”AJAX 请求的问题。我有一个带有多个组合的表单(“选择”标签)。我正在从 MySQL DB 加载每个组合的项目,并使用为我设计的特殊类。每个组合都有一个“+”按钮(用于打开弹出窗口并添加新条目)。当用户“保存”新值时,AJAX 请求应该运行,但是什么也没有发生。啊,另一个细节:当新值保存在数据库中时,弹出窗口会自动关闭。

这是弹出代码 (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>';
  }
?>

这是 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>&nbsp;</p>
        <p>&nbsp;</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>&copy; </em></strong>Todos los Derechos Reservados 2010- -</span></p>          
            </th>
          </tr>
        </table>  
        </form>    
       </td>
      </tr>
    </table>
    </body>
    </html>

AJAX 请求应重新加载“父表单”中的组合,以及 BD 的所有条目(包括新条目)。

我的问题是,我可以在弹出窗口中执行 AJAX 请求吗?或者我该怎么做?

提前致谢!

PS:抱歉我的英语,我不是“母语人士”。

I have a problem With a "Special" AJAX Request. I have a Form with several combos ("Select" tag). I'm loading the items for each combo from a MySQL DB, with a Special class designed for me. Each Combo has a "+" Button (For Open a Pop-Up and Add a new Entry). When the user "Saves" the new value, the AJAX request should run, but, nothing happen. Ah, another detail: When the new value it's saved in the DB, the pop-up automatically close.

This is The Pop-Up Code (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>';
  }
?>

And This is The HTML Code:

<!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>

The AJAX Request shoud reload the Combo in the "Parent-Form", with all of the entries of the BD (Included the new one).

My Question is, I Can do the AJAX Request in the Pop-Up? Or How Can I Do This?

Thanks in Advance!

PS: Sorry For My English, I'm Not a "Native-Speaker".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2024-10-04 19:32:38

在主窗口而不是弹出窗口中运行 Ajax 请求。例如,当您在弹出窗口中提交表单时,执行 window.opener.cargarTipoSistema();

Run the Ajax request in the main window not in the popup. So for example, when you submit the form in the popup, do a window.opener.cargarTipoSistema();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文