Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ajax请求后显示页面_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 在ajax请求后显示页面

Javascript 在ajax请求后显示页面,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我需要一个网页,用户可以修改数据库中已经捕获的数据。因此,我制作了一个包含所有数据列表的选项卡,当用户单击其中一个时,我想在一个包含匹配数据的页面中重定向用户 这是我的账单: <?php $conn_string = "host=localhost port=5432 dbname=test_postgre user=postgres password='1234'"; $dbconn = pg_connect($conn_string); $sql = "SELECT id_essa

我需要一个网页,用户可以修改数据库中已经捕获的数据。因此,我制作了一个包含所有数据列表的选项卡,当用户单击其中一个时,我想在一个包含匹配数据的页面中重定向用户

这是我的账单:

<?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>';
?>

我得到了所选数据的ID,如下所示:

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

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

$(文档).ready(函数(){
$('a')。单击(函数(){
var id_essai=$(this.attr('id');
$.post('traitement_modif_essai.php',{id_essai:id_essai});
});
});
现在,在另一个文件中,我想获取ID并显示正确的页面,但我想不起来

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

 echo $_SESSION['id_essai'];

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

您可以在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>

$(文档).ready(函数(){
$('a')。单击(函数(){
var id_essai=$(this.attr('id');
$.post('traitement\u modif\u essai.php',{id\u essai:id\u essai},function(){
window.location=“./essai_modif.php”;
});
});
});
在PHP中

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

 echo $_SESSION['id_essai'];    
?>

您可以在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>

$(文档).ready(函数(){
$('a')。单击(函数(){
var id_essai=$(this.attr('id');
$.post('traitement\u modif\u essai.php',{id\u essai:id\u essai},function(){
window.location=“./essai_modif.php”;
});
});
});
在PHP中

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

 echo $_SESSION['id_essai'];    
?>


是的,这就是你要找的。回答得好是的,这就是你要找的。回答得好