根据javascript确认的响应退出php脚本



我从html表单中获取值,在php中进行一些操作,并更新mysql表的记录。在更新之前,我要求用户使用javascript进行"确认"。如果用户按"取消",我不想更新记录。

,我试过以下几种

... some php code here
<script type=text/javascript>
    var to_disp = <?php echo json_encode($u_fields);?>;
    var r = confirm("Updating the fields >> " + to_disp.join());
    if (r != true){
        window.location.href = some-url;
    }
</script>
...updating the record here

注意:这在windows中运行良好。但是,当移动到linux时,这不起作用——页面被重定向到提到的url,但记录也在更新。

PHP代码在服务器端、Javascript客户端运行。

例如:创建一个带有提交按钮"确认"的客户端表单。首先将其发送到客户端,然后为该表单的操作创建一个php代码文件,该文件将更新/不更新记录。

最新更新