I want to get some JSON content from a URL using JavaScript (jQuery) Ajax, but it's always failing to load the data.
My code is very simple:
<div id="content">
loading...
</div>
console.log("jQuery Version: " + jQuery.fn.jquery);
$.ajax({
type: "GET",
url: "https://www.teamspeak.com/versions/server.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));
},
});
The page is always showing this content:
Failed to load data. {"readyState":0,"status":0,"statusText":"error"}
When I try dataType: "jsonp"
(with the P
) instead of dataType: "json"
, then it's showing this content:
Failed to load data. {"readyState":4,"status":200,"statusText":"load"}
So... It was successful, but it's still loading? I don't get it. When I open the above mentioned URL in my browser, I can see application/json
formatted data.
Check the result of the code here: https://jsfiddle.net/j2t91osz/1/