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 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!