jscript确认并通过AJAX调用PHP时如何更新$_SESSION值

经过多次尝试后,我需要帮助。单击事件后,我检查数据库中存在的数据并使用 jscript 弹出确认框。

当我点击“取消”时,如何让它工作,它没有显示我在confirm.php上设置的任何值?

https://img4.mukewang.com/64d5fdbe0001ebad04730188.jpg

单击“确定”确认并单击“取消”


j脚本代码:


if($row_count2 > 0)

{

    if ($row2["Status"] == "REJECTED")

    {

    <script type="text/javascript">

        if (!confirm('Lot No has been REJECTED before.. Double confirm to add the Lot No!!')) {

        var option = "NO";

        $.ajax({

            type: "POST", 

            url: "confirm.php",

            data: "value="+option,

            success: function (data) {

                alert(data);

            }         

        });

    }

    </script>

    }

}


$ll = $_SESSION['Confirm'];

echo "<script type='text/javascript'>alert('$ll');</script>";


if ($row_count2 < 1 || ($_SESSION['Confirm'] = "YES"))

{

    //my insert query is here...

}

这是在confirm.php里面:


<?php    

    session_start();

    

    $xx = $_REQUEST["value"];

    $_SESSION['Confirm'] = $xx;

    echo "<script type='text/javascript'>alert('$xx');</script>";

?>

我期望获得$_SESSION['Confirm']“否”的价值


默认$_SESSION['Confirm']值为 YES


alert(data)$_SESSION['Confirm']显示 $xx 为“否”,但当我在插入查询值之前在 if 条件上设置值警报时,值$_SESSION['Confirm']仍然保持为“是”


PIPIONE
浏览 83回答 1
1回答

芜湖不芜

而不是使用 JScript 警报,这真的很麻烦。我最终使用了模式弹出警报。<div class="modal-content">&nbsp; &nbsp; <div class="modal-header bg-secondary">&nbsp; &nbsp; &nbsp; &nbsp; <button type="button" class="close" data-dismiss="modal"></button>&nbsp; &nbsp; &nbsp; &nbsp; <h4 class="modal-title text-white ">Confirmation</h4>&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="modal-body">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <div class="box-body">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <form class="form-signin">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label for="txtLotNo" class="mr-sm-2 ml-sm-4">Lot No : '.$lotNo.' has been REJECTED before.. Double confirm to add the Lot No!!</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="text-center">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button type="button" id="getAdd" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#myAdd" data-id="YES'.$lotNo.$newLotNo.'" >YES</button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button type="button" id="getAdd" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#myAdd" data-id="NO" >NO</button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </form>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div></div>然后我使用 JScript 调用一个 php 文件,它可以完美地处理 data-id 。&nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; $(document).on('click','#getAdd',function(e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var per_id=$(this).data('id');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //alert(per_id);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#add-data').html('');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url:'addLot_func.php',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type:'POST',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data:'id='+per_id,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType:'html'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).done(function(data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#add-data').html('');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#add-data').html(data);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).fail(function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#add-data').html('<p>Error</p>');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; </script>&nbsp; &nbsp;在addLot_func.php中:&nbsp; &nbsp; if(isset($_REQUEST['id'])){&nbsp; &nbsp; &nbsp; &nbsp; $id=intval($_REQUEST['id']);&nbsp; &nbsp; &nbsp; &nbsp; $reject = $_REQUEST['id'];&nbsp; &nbsp; }&nbsp; &nbsp; else $reject = "";&nbsp; &nbsp; if(substr($reject,0,3) == "YES")&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; }&nbsp; &nbsp; else&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP