【问题标题】:php create button url from scriptphp从脚本创建按钮url
【发布时间】:2013-07-07 00:41:28
【问题描述】:

我目前使用脚本来生成两个需要传递到 url 中的变量。这两个变量是从一个数组中生成的。我想要做的类似于“下一步”按钮,当用户点击时,它会将用户带到生成的 url

my_page.html

<form action="next_to_go.php" method="get">
<button id="next_to_go" class="btn btn-warning" type="submit">Next To Go</button>
</form>

next_to_go.php 当前生成两个变量: url 的 $code 和 $num

$my_url = '/today.php?code='.$code.'&num='.$num;
header('location:'.$my_url);

我尝试过使用...在单独测试“next_to_go.php”时有效。但是当单击 my_page.html 中的按钮时,它不起作用。另外,我仍在搜索(和学习)ajax 解决方案...任何帮助将不胜感激!

编辑:使用 ajax 和 next_to_go.php 回显 url

$("#next_to_go").click(function(){

    $.ajax({
        type: 'POST',
        url: 'next_to_go.php',
        success: function(data) {
            window.location = href;
        }
    });
});

【问题讨论】:

  • 点击按钮会得到什么?
  • 什么都没有,只是重新加载当前页面。添加了一个ajax脚本

标签: php ajax url variables button


【解决方案1】:

比我想象的要容易..

在 html 内:

<a href="next_to_go.php" class="btn">Next</a>

在php内:

header('location:'.$my_url);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多