PHP 和 JavaScript - 重定向到动态 URL

标签 php javascript

只是一个简单的问题。

目前,我有一个登录脚本,可以重定向到dashboard.php,用户可以在其中单击按钮来检索预先选择的当前月份和年份的Google Analytics 统计信息。

2011 年 5 月的网址为:dashboard.php?month=May&year=2011&submit=Get+Statistics!

所以我想做的是让统计数据随页面一起加载,而不必单击按钮。

我能想到的唯一方法是更改​​登录脚本中的以下行:

// redirect to secure page
document.location='dashboard.php';

类似:

// redirect to secure page
document.location='dashboard.php' + <?php echo ?month=currentMonth&year=currentYear&submit=Get+Statistics! ?>';

月份和年份变量设置如下: $currentMonth = 日期('F'); $currentYear = 日期('Y');

但这不起作用,它只是正常转到dashboard.php。

有什么想法吗?

最佳答案

您缺少第二个字符串前面的单引号:

document.location='dashboard.php' + '<?php echo "?month=currentMonth&year=currentYear&submit=Get+Statistics!" ?>';

应该在 PHP 文件中工作。

关于PHP 和 JavaScript - 重定向到动态 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6174776/

相关文章:

javascript - IE 11 企业模式下未触发本地存储事件

php - Laravel 使用 PHP 链表实现 SplDoublyLinkedList();

php - 检查表单提交时是否存在用户名

PHP UTF-8 处理

javascript - 如何在不知道其 ID 的情况下从 JavaScript 中选择 HTML 元素?

javascript - Datepicker - 用户输入日期的 2 条规则

javascript - 如何打开带有 URL 的选项卡?

php - 在后台运行 PHP 脚本(不打扰用户)?

javascript - 将 html(文本)转换为 jQuery 对象 : lost value

javascript - Three.js 使用 raycaster intersectObjects 忽略被遮挡的对象