How To Get And Use A JSON Parameter Value From An API Request/response
I'm working on a website and want to display or hide a div-tag depending on a parameter value I can find in an API response. The link to the API information I need is https://api.h
Solution 1:
Your ajax call should look like this.
The media_is_live is in the result, not in your query.
$.ajax({
type: "GET",
dataType: "json",
url: "https://api.hitbox.tv/media/status/masta",
success: function(data){
if(data.media_is_live == "0") {
//Your code here
}
else {
//Your code here
}
}
});
Solution 2:
Try:
$(document).ready(function() {
$.ajax({
type: "GET",
dataType: "json",
url: "https://api.hitbox.tv/media/status/masta",
success: function(data){
if(data.media_is_live === "0") {
document.getElementById("player").style.visibility = "hidden";
}
else {
document.getElementById("player").style.visibility = "visible";
}
}
});
});
Post a Comment for "How To Get And Use A JSON Parameter Value From An API Request/response"