unter dem Code wird jedoch im Grunde genommen versucht, den Benutzerspeicherort von IP -Addrees zu holen und dann über AWS Dynamo DB über AWS Lambda -Funktion URL zu protokollieren. Die Website wird auf S3 als statische Website
gehostet. Der folgende Code funktioniert perfekt, wenn ich auf meinen Laptop -Browsern wie Chrome, Edge ausführt. Auf mobilen Browsern wird es jedoch überhaupt nicht geladen. Nur ein leerer Scrren. AddEventListener zweimal ein Problem oder fehlt mir etwas?
Code: Select all
const myModal = new bootstrap.Modal('#load-modal');
window.addEventListener('DOMContentLoaded',function () {
myModal.show();
});
document.addEventListener("DOMContentLoaded", function() {
// Fetch latitude and longitude based on IP address
fetch("https://ipapi.co/json")
.then(response => response.json())
.then(data => {
console.log(data.latitude)
console.log(data.longitude)
const bdcAPI = `https://api-bdc.net/data/reverse-geocode-client?
// latitude=${data.latitude}&
// longitude=${data.longitude}`
getAPI(bdcAPI)
})
.catch(error => {
console.error("Error fetching IP address:", error);
});
});
function getAPI(bdcAPI){
fetch(bdcAPI)
.then(response => response.json())
.then(data => {
console.log(data.countryName)
console.log(data.city)
functionURL(data.continentCode,data.continent,data.countryCode,
data.countryName,data.principalSubdivisionCode,data.principalSubdivision,data.city,data.locality)
})
.catch(error => {
console.error("Error fetching country and city name", error);
});
}
function functionURL(continentCode,continent,countryCode, countryName,
principalSubdivisionCode,principalSubdivision,city,locality){
const functionurl = `aws lambda function url`
console.log(functionurl)
fetch(functionurl)
.then(response => response.json())
.then(data => {
console.log('Location logged successfully!!')
})
.catch(error => {
console.error("Error calling function url:", error);
});
}