0

この関数 (ページ calendar.html) によって設定されている Cookie があります。

function bookit(id){
document.cookie='eventid' + "=" + id;
document.location.href ="/sys/account.php";
}

その後、ユーザーは account.php にリダイレクトされるため、サインインできるようになり、そのページで ID が使用されます。これが account.php にあるものです。

function getCookieValue(key)
{
    currentcookie = document.cookie;
    if (currentcookie.length > 0)
    {
        firstidx = currentcookie.indexOf(key + "=");
        if (firstidx != -1)
        {
            firstidx = firstidx + key.length + 1;
            lastidx = currentcookie.indexOf(";",firstidx);
            if (lastidx == -1)
            {
                lastidx = currentcookie.length;
            }
            return unescape(currentcookie.substring(firstidx, lastidx));
        }
    }
    return "";
}

alert(getCookieValue("eventid"));

ジレンマは次のとおりです。calendar.htmlを更新すると、たとえば、そのイベントの値である51がアラートに返されますが、account.phpを更新すると、次のように表示されます。基本的なjavascriptに、その値を渡す方法がわかりません。Cookie を使用するのが正しい方法だと思いましたが、うまくいきません。私のコードにはエラーがありません。

4

0 に答える 0