【问题标题】:php action code not working with javascript confirmAction()php 操作代码不适用于 javascript confirmAction()
【发布时间】:2021-10-26 21:37:10
【问题描述】:

我有这个 php 文件,它假设有一个按钮可以通过调用 JavaScript 内置函数来执行一些结帐功能操作

<a href="index.php" class="btn btn-danger btn-xs" > onclick="confirmAction()" <i class="icon-edit">Check out</a>

我像这样使用confirmAction()

<script>
                        // The function below will start the confirmation dialog
                        function confirmAction() {
                            let confirmAction = confirm("Dose the maintenance finished yet?");
                            
                            if (confirmAction) {
                                
                                alert("Action Done")
                        
                            } 
                            else {
                                alert("Action canceled");
                            }
                        }
                    </script>

如果用户按下 ok 我想做 php 代码 哪个应该做后期操作

controller.php?action=checkout&code=<?php echo $result->CONFIRMATIONCODE; ?>

但我没有成功地使它在 TRUE 的情况下在 javascript 函数中工作

基本上我尝试在没有 标签的情况下运行 php 代码,但我失败了

有什么建议吗? 谢谢

【问题讨论】:

  • 我在代码中的任何地方都没有看到对controller.php 的引用。您是否希望将用户重定向到该页面?向该页面发出 AJAX 请求?还有什么?我不清楚你希望这段代码做什么而它没有做什么。

标签: javascript php html css web


【解决方案1】:

使用如下代码,如果您想在取消事件中重定向,请添加如下代码:window.location.href = 'http://www.google.com';

表格:

    <form method="POST" action="controller.php" id="myForm">
  <input type="hidden" name="action" value="checkout"> 
  <input type="hidden" name="code" value="put code here"> 
  <a href="javascript:void(0)" class="btn btn-danger btn-xs" onclick="return confirmAction()" ><i class="icon-edit">Check out</i></a>
</form>

脚本:

function confirmAction() {
                        let confirmAction = confirm("Dose the maintenance finished yet?");
                        
                        if (confirmAction) {
                            
                            alert("Action Done");
                            document.getElementById("myForm").submit();
                        } 
                        else {
                            alert("Action canceled");
                            return false;
                        }
                    } 

【讨论】:

    猜你喜欢
    • 2017-01-22
    • 2021-03-23
    • 2017-05-23
    • 1970-01-01
    • 2019-05-26
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多