0

我有一个 php 页面(calendar.php),它使用 javascript 加载 php 日历(calendar_start.php)并在页面中心显示日历。

我正在尝试在 calendar_start.php 页面上获取一个变量,但是我无法访问可以从 calendar.php 页面访问的变量。

以下是 calendar.php 上用于生成 canendar_start.php 的脚本之一:

<script language="javaScript" type="text/javascript">
function initialCalendar(){
    var hr = new XMLHttpRequest();
    var url = "calendar_start.php";
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var year = currentTime.getFullYear();
    showmonth = month;
    showyear = year;
    var vars = "showmonth="+showmonth+"&showyear="+showyear;
    hr.open("POST", url, true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var return_data = hr.responseText;
            document.getElementById("showCalendar").innerHTML = return_data;
        }
    }
    hr.send(vars);
    document.getElementById("showCalendar").innerHTML = "processing...";
}
</script>

以下是我生成日历的页面 calendar.php 的一部分:

<body onLoad="initialCalendar(<?php $_GET['page']; ?>);">

我无法获取 calendar_start.php 上的变量,非常感谢任何帮助。

最诚挚的问候,瑞恩

编辑::

这可能会有所帮助,这是我尝试在 calendar_start.php 上显示变量时出现的错误

注意:未定义索引:C:\wamp\www\project\calendar_start.php 中的页面

4

1 回答 1

0

Change $_GET['page'] to $_REQUEST['page'].

$_REQUEST combines $_GET and $_POST together (with $_POST taking precedence). That way you won't have to worry about backward comaptibility if you change it in the future.

It is, however, a bad idea to echo ANY of these variable unsanitized to users browser.

EDIT:

Although your main problem is that you forgot the "echo" command in front of the variable.

于 2013-04-13T22:37:19.690 回答