如何在不刷新页面的情况下在同一php文件中发送每个帖子的html值

时间:2019-12-12 18:47:32

标签: php html ajax post

我有一个带有按钮的表,我想根据激活的按钮发送一个值,以便在不刷新页面的情况下在同一文件中执行php查询,该怎么办?? ..帮助。

我正在尝试使用Ajax,但它对我不起作用。

在表中保存的按钮中,我在按钮的值中分配每一行的ID,该值我想通过Ajax发送给同一文件中的php代码片段,以进行查询并填写一种详细记录每条记录的表格。

<?php
    session_start();

?>


<!DOCTYPE html>
<html>
<head>
    <script src="./funciones.js"></script>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <link rel="stylesheet" href="css/style_table.css">
    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
   <script>function ver(e){
        document.getElementById("ver").style.display = "block";
        var id = e.value;
           $.ajax({
                url: <?= json_encode($_SERVER['PHP_SELF']) ?>,
                data:{ver:id},
                type: 'POST',
                dataType: 'json',
                }).done(function(data) {

                });
        }
        function closeVer() {
          document.getElementById("ver").style.display = "none";
        }

        function openForm() {
          document.getElementById("myForm").style.display = "block";
        }

        function closeForm() {
          document.getElementById("myForm").style.display = "none";
        }
   
        function objetoAjax(){
            var xmlhttp = false;
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {

                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                    xmlhttp = false; }
            }

            if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
              xmlhttp = new XMLHttpRequest();
            }
            return xmlhttp;
        }

        function enviarDatos(e){
            document.getElementById("ver").style.display = "block";
                idn = document.e.value;
                ajax = objetoAjax();

                ajax.open("POST", <?= json_encode($_SERVER['PHP_SELF']) ?>, true);
                ajax.onreadystatechange = function() {

                    if (ajax.readyState == 4){

                    }
                }
                ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");


                ajax.send("&ver="+idn)
        }
       
    </script>
    
</head>
<body>
    
<h3 class="titulo"> Intervenciones </h3>

<form name="back" method="post" action="Home.html" class="regresarform">
    <input class="btn__submit" type="submit" value="Regresar">
</form>

<table border="2">
    <tr>
        <th><b>id</b> </th>
        <th><b>carpeta</b></th>
        <th><b>numeros intervenidos</b></th>
        <th><b>Nombre Juez</b></th>
        <th><b>Numero de Resolucion</b></th>
        <th><b>Objetivos</b></th>
    </tr>
    <?php

    
    $conexion=mysqli_connect("192.168.0.13", "FGE", "MARJ901201", "mps");
    $criterio = $_POST['buscarporinter'];
    $variable_B = $_POST['dateinterv'];
    
    if($criterio === "1"){
        $FLAG_B = "carpeta";
    }
    elseif ($criterio==="2"){
        $FLAG_B = "numeros";
    }elseif ($criterio === "3") {
        $FLAG_B = "juez";
    }elseif ($criterio ==="4") {
        $FLAG_B = "resolucion";
    }elseif ($criterio ==="5") {
        $FLAG_B = "fechainicio";
    }elseif ($criterio ==="6") {
        $FLAG_B = "fechatermino";
    }elseif ($criterio ==="7") {
        $FLAG_B = "duracion";
    }elseif ($criterio ==="8") {
        $FLAG_B = "informeinicial";
    }elseif ($criterio ==="9") {
        $FLAG_B = "informemes1";
    }elseif ($criterio ==="10") {
        $FLAG_B = "informemes2";
    }elseif ($criterio ==="11") {
        $FLAG_B = "informemes3";
    }elseif ($criterio ==="12") {
        $FLAG_B = "terminacion";
    }elseif ($criterio ==="13") {
        $FLAG_B = "conclusion_ant";
    }elseif ($criterio ==="14") {
        $FLAG_B = "objetivos";
    }

    
    $sql="SELECT *FROM intervenciones where $FLAG_B like '$variable_B%'";
    $result = mysqli_query($conexion, $sql);
 
    $A = array();
    $count = 0;
    while($mostrar1=mysqli_fetch_array($result)){
        array_push($A, $mostrar1['idintervenciones']);
    ?>
    <tr>
        <td><?php echo $mostrar1['idintervenciones'] ?></td>
        <td><?php echo $mostrar1['carpeta'] ?></td>
        <td><?php echo $mostrar1['numeros'] ?></td>
        <td><?php echo $mostrar1['juez'] ?></td>
        <td><?php echo $mostrar1['resolucion'] ?></td>
        <td><?php echo $mostrar1['objetivos'] ?></td>
        <td><button value="<?php echo $mostrar1['idintervenciones']?>" class="edit" onclick="openForm()">EDITAR</button>
            <button class="edit"  onclick="enviarDatos(this)" id="<?php echo  $mostrar1['idintervenciones']; ?>" value="<?php echo  $mostrar1['idintervenciones']; ?>"  >VER</button>
    </tr>
    <?php
    $count++;
    }
    
    ?>
</table>

<div class="form-popup" id="myForm">
  <form class="form-container" action="" enctype="multipart/form-data" method="POST">
    <h4>Agregar Avance</h4>
    <input type="text" placeholder="Agregar Avance" name="avances" required>
    <button type="submit" class="btn">GUARDAR</button>
    <button type="button" class="btn cancel" onclick="closeForm()">CANCELAR</button>
  </form>
</div>
    
   
    
<div class="contain" id="ver">
    <?php
        print("....".$_POST['ver']);
        if (isset($_POST['ver'])) {
            /* Agregamos los datos recibidos a la variable de sesión */
            array_push($_SESSION['datos'], $_POST['ver']);
            $id = $_POST['ver'];
            print($id);
            header('Content-type: application/json; charset=utf-8');
            $conexion=mysqli_connect("192.168.0.13", "FGE", "MARJ901201", "mps");
            $sql2="SELECT *FROM intervenciones where idintervenciones = $id";
            $result2 = mysqli_query($conexion, $sql2);
            $mostrar=mysqli_fetch_row($result2);  
            die(json_encode(true));
        }
    

    ?>
  <div class="wrapper" name="formulario-o">
    <div class="contacts">
      <h3>Usuario: ----</h3>

      <ul>
        <li>Inteligencia. UECS</li>
        <li>Registro de intervenciones</li>
      </ul>
      <p>
        <button onclick="closeVer()">CERRAR</button>
      </p>
    </div>

    <div class="form">
      <h3>Información de  Intervención</h3>
      <h6></h6>
      <form class="formulario" action="" enctype="multipart/form-data" method="POST">
        <p>
          <label for="">Carpeta</label>
          <input type="text" readonly="readonly" value="<?php echo $mostrar[1]?>">
        </p>
        <p>
          <label for="">Numeros Intervenidos</label>
          <input type="text"readonly="readonly" value="<?php echo $mostrar[2]?>">
        </p>
        <p>
          <label for="">Juez</label>
          <input type="text"readonly="readonly" value="<?php echo $mostrar[3]?>">
        </p>
        <p>
          <label for="">Numero de Resolucion</label>
          <input type="text" readonly="readonly" value="<?php echo $mostrar[4]?>">
        </p>
        <p>
          <label for="">Fecha de inicio</label>
          <input type="text"readonly="readonly" value="<?php echo $mostrar[5]?>">
        </p>
        <p>
          <label for="">Fecha de terminacion </label>
          <input type="text"readonly="readonly" value="<?php echo $mostrar[6]?>">
        </p>
        <p>
          <label for="">Duracion de Intervencion</label>
          <input type="text"readonly="readonly" value="<?php echo $mostrar[7]?>">
        </p>
        <p>
          <label for="">Informe Inicial</label>
          <input type="text"readonly="readonly" value="<?php echo $mostrar[8]?>">
        </p>
        <p>
          <label for="">Informe mes 1</label>
          <input type="text" readonly="readonly" value="<?php echo $mostrar[9]?>">
        </p>
        <p>
          <label for="">Informe mes 2</label>
          <input type="text" readonly="readonly" value="<?php echo $mostrar[9]?>">
        </p>
        <p>
          <label for="">Informe mes 3</label>
          <input type="text" readonly="readonly" value="<?php echo $mostrar[10]?>">
        </p>
        <p>
          <label for="">Terminacion</label>
          <input type="text" readonly="readonly" value="<?php echo $mostrar[11]?>">
        </p>
        <p>
          <label for="">Conclusion Anticipada</label>
          <input type="text" readonly="readonly" value="<?php echo $mostrar[12]?>">
        </p>
        <p>
          <label for="">Objetivos</label>
          <input type="text" readonly="readonly" value="<?php echo $mostrar[13]?>">
        </p>
        <p>
          <label for="">Avances</label>
          <textarea name="" id="" cols="30" rows="7" readonly="readonly" value="<?php echo $mostrar[14]?>"></textarea>
        </p>
      </form>
    </div>
  </div>
</div>    

</body>
</html>

0 个答案:

没有答案