只是一个简单的问题。
目前,我有一个登录脚本,可以重定向到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/