简体   繁体   English

在ajax请求后显示页面

[英]Display a page after an ajax request

I need a web page where users can modify a data already captured in database. 我需要一个网页,用户可以在其中修改数据库中已捕获的数据。 So I made a tab with the list of every data and when a user click on one, I want to redirect the user in a page with matching data. 因此,我制作了一个包含所有数据列表的选项卡,当用户单击一个数据时,我想在具有匹配数据的页面中重定向用户。

So this is my tab : 这是我的标签:

<?php

$conn_string = "host=localhost port=5432 dbname=test_postgre user=postgres password='1234'";
$dbconn = pg_connect($conn_string);

$sql = "SELECT id_essai, nom_local_essai, thematique FROM public.essai";
$res = pg_query($sql) or die("Pb avec la requete: $sql");

echo'<table class="table table-hover" border="1">';
echo'<thead><tr><th>id_essai</th><th>Nom local</th><th>Thématique</th></tr></thead>';
while ($data = pg_fetch_array($res))
{

        echo'   <tbody>
                <tr>
                    <td><a id="'.$data['id_essai'].'">
                        '.$data['id_essai'].'
                    </a></td>
                    <td>
                        '.$data['nom_local_essai'].'
                    </td>           
                    <td>
                        '.$data['thematique'].'
                    </td>
                </tr>
        </tbody>                    
        ';
    }
echo'</table>';
?>

And I get the ID of the data selected like this : 我得到这样选择的数据的ID:

<script>
$(document).ready(function(){
    $('a').click(function(){
        var id_essai = $(this).attr('id');

        $.post('traitement_modif_essai.php',{id_essai:id_essai});
    });
});
</script>

Now, on the other file, I want to get the ID and display the right page, but I can't get thought. 现在,在另一个文件上,我想获取ID并显示正确的页面,但我没想到。

<?php
 session_start();
 $_SESSION['id_essai'] = $_POST['id_essai'];

 echo $_SESSION['id_essai'];

 header('Location:essai_modif.php');    
?>

You can redirect the user after the session has been set by you in the PHP in the javascript callback of post 您可以在PHP的post的JavaScript回调中设置会话后,重定向用户

<script>
$(document).ready(function(){
    $('a').click(function(){
        var id_essai = $(this).attr('id');

        $.post('traitement_modif_essai.php',{id_essai:id_essai}, function(){
            window.location = "./essai_modif.php";
        });
    });
});
</script>

and in the PHP 并在PHP中

<?php
 session_start();
 $_SESSION['id_essai'] = $_POST['id_essai'];

 echo $_SESSION['id_essai'];    
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM