doudan4834 2013-01-03 05:24
浏览 21
已采纳

使用onclick发布变量?

How can I $_POST information from one page to another by clicking a link? No forms or submit boxes, just if the end user clicks on a link, it will post pertinent information in the opened link.

Pseudocode, but:

//On first page
<a href="./page.php" onclick="post" value="var">Click me!</a>
...
//On the page the above links to
$variable = $_POST["var"];

Something that I considered is the following, which although less than pretty, works. I'd like it so it's a post and not a get.

//On first page
<a href="./page.php?var=<?php echo $variable; ?>">Click me!</a>
...
//On second page
$variable = $_GET["var"];
  • 写回答

6条回答 默认 最新

  • duande1985 2013-01-03 05:53
    关注

    Try this :

    <a href="link.php" class="post">submit content using link</a>
    
     <script type="text/javascript">
                jQuery(document).ready(function($){
                    $(".post").on("click",function(){
                        $.ajax({
                            url: "http://www.yourwebsite.com/page.php",
                            type: "POST",
                            data: { name: "John", location: "Boston" },
                            success: function(response){
                                  //do action  
                            },
                            error: function(){
                                  // do action
                            }
                        });
                    });
                });
            </script>
    

    Reference Link

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程