![]() |
|
Getting Json request to work - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: Getting Json request to work (/Thread-Getting-Json-request-to-work) Pages:
1
2
|
RE: Getting Json request to work - hacxx - 04-10-2018 (04-09-2018, 08:40 PM)Pikami Wrote: It won't be the case, I used this API in my site 2 weeks ago: http://quotes.rest/ Can you provide a code sample? RE: Getting Json request to work - Pikami - 04-10-2018 (04-10-2018, 02:56 PM)hacxx Wrote:(04-09-2018, 08:40 PM)Pikami Wrote: It won't be the case, I used this API in my site 2 weeks ago: http://quotes.rest/ sure Code: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
</head>
<body>
<div class="container">
<h1 id="demo">place holder</h1>
</div>
<script>
fetch('https://jsonplaceholder.typicode.com/comments?postId=1')
.catch(function(myJson) {
document.getElementById("demo").innerHTML = "Oh no! Some shit happened :(";
})
.then(function(response) {
return response.json();
})
.catch(error => console.error('Error:', error))
.then(function(myJson) {
console.log(myJson);
document.getElementById("demo").innerHTML = myJson[0].body;
});
</script>
</body>
</html>RE: Getting Json request to work - Synthx - 04-10-2018 Okay, this might be a stupid question, but I'm here to learn, and this is an opportunity for someone to feel like they're contributing to the community... My question is, what would you use json requests for, and what languages could you use them with? Edit: Even if someone made a thread on it, that'd be nice. RE: Getting Json request to work - Pikami - 04-10-2018 (04-10-2018, 06:07 PM)Synthx Wrote: Okay, this might be a stupid question, but I'm here to learn, and this is an opportunity for someone to feel like they're contributing to the community... json is mostly used while communicating with an API Example: you have some reactive web page where you need to reload data every few seconds, you don't want to reload the whole page, so you use javascript to get that data trough an API and update just that. There are many more use cases, this is only one example. If you have enough interest in this or want to learn more you can always PM me
RE: Getting Json request to work - Synthx - 04-10-2018 (04-10-2018, 06:18 PM)Pikami Wrote:(04-10-2018, 06:07 PM)Synthx Wrote: Okay, this might be a stupid question, but I'm here to learn, and this is an opportunity for someone to feel like they're contributing to the community... Thanks man, I am interested, but I'll PM you sometime within the next month or so about it. Unless I forget, lol. RE: Getting Json request to work - phyrrus9 - 04-11-2018 (04-09-2018, 02:00 PM)hacxx Wrote: Dear god PLEASE format that.... (04-10-2018, 06:18 PM)Pikami Wrote:(04-10-2018, 06:07 PM)Synthx Wrote: Okay, this might be a stupid question, but I'm here to learn, and this is an opportunity for someone to feel like they're contributing to the community... I disagree. JSON is an encoding used to describe an object. It doesn't need to be used with an API, in fact many NoSQL implementations use it. It can be helpful when you want to describe something in a user-readable format, rather than using a plist. It can also be nice if you are creating software configuration schemas and you don't want the user to have to specify all of the variables. RE: Getting Json request to work - Pikami - 04-11-2018 (04-11-2018, 12:49 AM)phyrrus9 Wrote:(04-09-2018, 02:00 PM)hacxx Wrote: I made a mistake, thanks for correcting me, I didn't state that it "needs" to be used with an API tho. RE: Getting Json request to work - Blink - 04-11-2018 (04-10-2018, 06:18 PM)Pikami Wrote:(04-10-2018, 06:07 PM)Synthx Wrote: Okay, this might be a stupid question, but I'm here to learn, and this is an opportunity for someone to feel like they're contributing to the community... One should note that while it is often used for APIs, it is also used a lot for configuration files and data storage. |