用javascript函数执行php文件

 书友73428983 发布于 2023-02-13 15:44

我想在javascript函数中执行php文件.代码如下所示:

Cancel



但是当我点击取消按钮时,clear.php没有被执行.我该如何从这里出来?

1 个回答
  • 完整和有效的回答你的问题:

    <html>
    <head>
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script language="javascript">
            function cancelClicked() {
                // function below will run clear.php?h=michael
                $.ajax({
                    type: "GET",
                    url: "clear.php" ,
                    data: { h: "michael" },
                    success : function() { 
    
                        // here is the code that will run on client side after running clear.php on server
    
                        // function below reloads current page
                        location.reload();
    
                    }
                });
            }
        </script>
    </head>
    <body>
        <a id="cancel" href="#" onclick="cancelClicked()">Cancel</a>
    </body>
    </html>
    

    2023-02-13 15:50 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有