Ich bin ziemlich gut mit HTML und CSS, aber absolut keine Erfahrung mit Javascript.Wie zeige ich Json API Daten in HTML an?
Ich mag das Datum von dieser API in eine HTML-Seite
http://api.travelpayouts.com/data/routes.json?token=PutHereYourToken
Dies ist erhalten angezeigt, wie ich ohne Erfolg bin versucht, bis jetzt.
var getJSON = function(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
resolve(xhr.response);
} else {
reject(status);
}
};
xhr.send();
});
};
getJSON('https://api.travelpayouts.com/data/routes.json?token=mytoken').then(function(data) {
alert('Your Json result is: ' + data.result);
result.innerText = data.result;
}, function(status) {
alert('Something went wrong.');
});
<body>
<div class="container">
<div id="result" style="color:red"></div>
</div>
</body>
Danke :)
https://stackoverflow.com/help/how-to-ask – tech2017
https : //developer.mozilla.org/en-US/docs/AJAX – Thiatt
@sloane Sobald Sie tatsächlich etwas Mühe gezeigt haben. Es ist unsere Aufgabe zu helfen, sobald Sie gezeigt haben, dass Sie es zuerst selbst versucht haben. Du hast das hier nicht getan. – Carcigenicate