html olarak url girince veriyi göstermesi lazım
deneme olarak şu adresi yazdım
https://jsonplaceholder.typicode.com/todos/1 <body>
<input type="text" id="msm" placeholder="url gir">
<button onclick="buton()">veri çek</button>
<div id="hedef"></div>
<script>
function buton() {
var x = document.getElementById("msm").value;
veriCek(x);
}
function veriCek(URL) {
fetch(URL)
.then(response => response.json())
.then(data => {
document.getElementById('hedef').innerText = JSON.stringify(data, null, 2);
})
.catch(error => console.error('bir sorun oluştu:', error));
}
</script>
</body>Başlangıçta veri ile yüklemek istersende bu şekilde oynayabilirsin
<script>
//değişkeni üste al
var x = "https://jsonplaceholder.typicode.com/todos/1"
function buton() {
x = document.getElementById("msm").value;
veriCek(x);
}
function veriCek(URL) {
fetch(URL)
.then(response => response.json())
.then(data => {
document.getElementById('hedef').innerText = JSON.stringify(data, null, 2);
})
.catch(error => console.error('bir sorun oluştu:', error));
}
//Dom yüklendiğinde vericek fonksiyonunu çalıştırsın
//Böylece sayfa ilk yüklendiğinde boş gelmez veri ile gelir yeni url girince değiştirir.
document.addEventListener('DOMContentLoaded',veriCek(x))
</script>