• 14-08-2023, 17:38:16
    #1
    const targetCountry = 'TR';
    
    fetch('https://api64.ipify.org?format=json')
      .then(response => response.json())
      .then(data => {
        const userIP = data.ip;
    
    
        fetch(`https://ipinfo.io/${userIP}/country?token=`)
          .then(response => response.text())
          .then(country => {
      const targetElement = document.querySelector("#test")
            if (country === targetCountry) {
              console.log('çalıştı');
            } else {
              console.error('hata');
            }
          });
      })
      .catch(error => {
        console.error('IP alınırken bir hata oluştu:', error);
      });
    Merhabalar. burda if şartım tutmasına rağmen (TR=TR) olmasına rağmen else çalışıyor. nedeni ne olabilir
  • 14-08-2023, 17:39:50
    #2
    merhaba birde böyle denermisin

    const targetCountry = 'TR';
    
    fetch('https://api64.ipify.org?format=json')
      .then(response => response.json())
      .then(data => {
        const userIP = data.ip;
    
        return fetch(`https://ipinfo.io/${userIP}/country?token=79e4ca65674d68`);
      })
      .then(response => response.text())
      .then(country => {
        const targetElement = document.querySelector("#test");
        if (country.trim() === targetCountry) {
          console.log('çalıştı');
          targetElement.textContent = 'çalıştı'; 
        } else {
          console.error('hata');
          targetElement.textContent = 'hata'; 
        }
      })
      .catch(error => {
        console.error('IP alınırken bir hata oluştu:', error);
      });
    • hakantapan
    hakantapan bunu beğendi.
    1 kişi bunu beğendi.
  • 14-08-2023, 17:41:10
    #3
    çok teşekkür ederim. çalıştı.
  • 14-08-2023, 17:41:56
    #4
    hakantapan adlı üyeden alıntı: mesajı görüntüle
    çok teşekkür ederim. çalıştı.
    rica ederim iyi forumlar
    • hakantapan
    hakantapan bunu beğendi.
    1 kişi bunu beğendi.
  • 14-08-2023, 18:13:52
    #5
    hakantapan adlı üyeden alıntı: mesajı görüntüle
    const targetCountry = 'TR';
    
    fetch('https://api64.ipify.org?format=json')
      .then(response => response.json())
      .then(data => {
        const userIP = data.ip;
    
    
        fetch(`https://ipinfo.io/${userIP}/country?token=79e4ca65674d68`)
          .then(response => response.text())
          .then(country => {
      const targetElement = document.querySelector("#test")
            if (country === targetCountry) {
              console.log('çalıştı');
            } else {
              console.error('hata');
            }
          });
      })
      .catch(error => {
        console.error('IP alınırken bir hata oluştu:', error);
      });
    Merhabalar. burda if şartım tutmasına rağmen (TR=TR) olmasına rağmen else çalışıyor. nedeni ne olabilir
    tokeni silseniz daha iyi olur sanki. Başkaları kullanmasın ?