次のように、メインファイル index.php を持つ Web ページを開発しています。
include('UserClass.php');
include('html/top.php');
$user = new User();
if (isset($_POST['user'], $_POST['pass']))
{
$user->login($_POST['user'], $_POST['pass']);
}
if ($user->logged != 1)
{
include('html/forms/login.html');
include('html/forms/register.html');
include('html/calendar.php');
}
これは私のajaxスクリプトです:
function nextMonth()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("text").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "html/calendar.php", true);
xmlhttp.send();
}
nextMonth() をトリガーするボタンをクリックすると、エラーが発生しました:
致命的なエラー: 41 行目の /var/www/.../html/calendar.php の非オブジェクトに対するメンバー関数 check_date() の呼び出し
つまり、オブジェクト user が存在しないため、User クラスのメソッドを使用できません。ユーザーがカレンダービューを翌月に変更しようとするたびにログアウトするため、calendar.php 内に User の新しいインスタンスを作成することはできません。このすべての AJAX を行うときに、index.php からオブジェクトを保存/渡すにはどうすればよいですか? ありがとう!