JavaScript: Get JSON from URL
by acdcjunior
HTML
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<div id="content">
loading...
</div>
JavaScript
console.log("jQuery Version: " + jQuery.fn.jquery);
$.ajax({
type: "GET",
url: "https://api.allorigins.win/get?url=" + encodeURIComponent("https://www.teamspeak.com/versions/client.json"),
dataType: "json",
success: function(data){
$("#content").html(data);
console.log("SUCCESS: " + JSON.stringify(data));
},
error: function(data){
$("#content").html("Failed to load data. " + JSON.stringify(data));
console.log("ERROR: " + JSON.stringify(data));
},
complete: function(data){
console.log("COMPLETED: " + JSON.stringify(data));
},
});