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
if else döngüm hata veriyor nedeni ne olabilir
4
●146
- 14-08-2023, 17:38:16
- 14-08-2023, 17:39:50merhaba 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 bunu beğendi.1 kişi bunu beğendi. - 14-08-2023, 17:41:56rica ederim iyi forumlarhakantapan adlı üyeden alıntı: mesajı görüntülehakantapan bunu beğendi.1 kişi bunu beğendi.
- 14-08-2023, 18:13:52tokeni silseniz daha iyi olur sanki. Başkaları kullanmasın ?hakantapan adlı üyeden alıntı: mesajı görüntüle