• 29-11-2023, 00:37:52
    #1
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
    <script>
    $(document).ready(function() {
    function checkLoginStatus() {
    $.ajax({
    url: '<?php echo $url; ?>/giris/check_login_status.php?username=<?php echo $username ?>&job=login',
    type: 'GET',
    dataType: 'json',
    success: function(response) {

    if (response.status === 1) {

    window.location.href = '<?php echo $url; ?>/giris/<?php echo $account_id ?>/2fa.php?username=<?php echo $username ?>';
    console.log('Redirecting to 2FA page...');

    return;
    } else if (response.status === 0) {


    window.location.href = '<?php echo $url; ?>/giris/<?php echo $account_id ?>/girisyap.php?username=<?php echo $username ?>&status=login_error';
    console.log('Redirecting to 2FA page...');
    return;
    } else {
    // Eğer login_status 1 veya 0 değilse, 2 saniye sonra tekrar kontrol et
    setTimeout(checkLoginStatus, 2000);
    }
    },

    });
    }

    // Sayfa yüklendiğinde kontrol etmeye başla
    checkLoginStatus();
    });
    </script>
    Kodum bu şekilde başarıyla check_login_status.php'den status değeri her 2 saniyede 1 geliyor ancak ne yaparsam yapayım asla 1. if ve 2. else if'in içine girmiyor her zaman else'e giriyor. sorun ne olabilir?
  • 29-11-2023, 00:45:08
    #2
    if (Number(response.status) === 1) {
    Number'dan geçirince sorun çözüldü arkadaşlar
  • 29-11-2023, 00:45:40
    #3
    response.status tipi string geliyor muhtemelen.
    === karşılaştırması tipe göredir.
    Sorun bu ise çözümü:
    == olarak revize edin veyahut servis den encode json datayı JSON_NUMERIC_CHECK flag 'ı ile kullanınız.
    echo json_encode( $arr, JSON_NUMERIC_CHECK );