JSON feed retreaval from URL

Hi guys,

I’m very new to programming and I try to research also other stuff. I’m lost with one thing that is what I heared quite easy. I would like to get JSON feed from one URL. I got a clue that I can use browser console but somehow I’m lost. I will be very happy for any kind of help :slight_smile:
As I said I’m at a very beginning of programming so some hard stuff would make it owrse :slight_smile:

thanks

Which URL? What is this for? JSON is indeed very easy, but AJAX calls can be confusing for people who already have a handle on the basics, so this might not be the best project to tackle right now.

Everything what I’d like to see is which data points are used on that specific website but I don’t want to reveal the website. For example we can take http://www.mapstd.com/ (I just picked one website that uses JS :slight_smile: )

As far as i know website have to have API to be able call like this website http://openweathermap.org/api and they have document for how to call their API.

I think you are confused about what this all means, and I’m not comfortable with the fact that you don’t want to say which website you’re trying to get data from. For now, I’ll ignore the latter problem and focus on the first one.

You cannot request arbitrary data from a server (at least, you’re not supposed to, but what colloquially understand as “hacking” is doing just this). When you get JSON data from a server, it’s because there’s a program running which responds to your request for such data. These programs define the requests we can send, and this definition is known as the API. So, I can send a request to tumblr.com because they have a documented API. The site you’ve linked to doesn’t seem to offer the same, so there’s no way of getting data in the way you want it.

All that said, any time you visit a page with your browser, you’re already getting a bunch of data from it, it’s just not in JSON format. You can took at all of the code that runs in your browser from the developer console, but you won’t necessarily have access to the data used to populate the application.

1 Like

You can get immediate API responses with a chrome app called Postman which is very good to make CRUD requests to a server and get either XML, HTML or JSON as response.

In your app, you’d need to use a request API, the browser’s javascript has one and it’s called XMLHTTP, jQuery makes it very simple with its $.getJSON or $.ajax methods but everything boils down to sending the xmlhttp request, waiting for a positive send and then acting upon a response code (400 or 500 error codes, 200 for succes) which when it’s 200 to 202 I think, means something went OK and if the server sends back a response you can use it, if it’s JSON, you have to parse it with JSON.parse() or if you use jQuery, it does it automatically:

jQuery

$.getJSON(url, function(data) {
  console.log(data);
});

If you want vanilla JS snippets, you can google them but be careful with JSONP APIs that require you to use a callback, in vanilla JS that’s a bit hard to wrap your head around as you basically append a script tag to your page, send the request wrapped inside a javascript function and it comes back. Usually, JSONP APIs ask you to use a &callback=foo (or &jsonp=foo in the case of the Forismatic API) in the query URL or something like that