DB から更新された num を取得するために Ajax を使用しようとしています。
主な機能は次のとおりです。
function checkInvitations() {
    if (username ="-1") {
        username = document.getElementById("username").value;
    }
    req.open('GET', 'check_num_of_invitations.php?username='+username);
    req.onreadystatechange = handleNumOfInvitationsResponse;
    req.send(null);
}
関数は HTML ファイルから呼び出されます ...
呼び出された関数 ( handleNumOfInvitationsResponse) :
function handleNumOfInvitationsResponse() {
if(req.readyState == 4) {
    // update div in HTML
} else {
    // update div in HTML
}
setTimeout(function(){checkInvitations();}, 5000);
}
への再帰呼び出しに注意してくださいcheckInvitations。
最初の試行では、応答は 4 を返し、すべてが機能し、それ以降は 2 が返されます。
ありがとうございます