I want to get a json from a url. As an example I want to get the json of this url: http://csgobackpack.net/api/GetItemPrice/?currency=USD&id=AK-47%20|%20Wasteland%20Rebel%20(Battle-Scarred)&time=7
And how do I do this in JavaScript now!
I want to get a json from a url. As an example I want to get the json of this url: http://csgobackpack.net/api/GetItemPrice/?currency=USD&id=AK-47%20|%20Wasteland%20Rebel%20(Battle-Scarred)&time=7
And how do I do this in JavaScript now!
If you are using the same domain (i.e. it is your website and you are under the same domain), then you just need to make an AJAX call like this :
$.ajax({
url: 'http://csgobackpack.net/api/GetItemPrice/?currency=USD&id=AK-47%20|%20Wasteland%20Rebel%20(Battle-Scarred)&time=7&callback=testCallback',
success: function (data) {
// Do whatever you want to do with the data here
}
});
Don't forget to include Jquery.
If you are on a different domain (and I suppose it is your case) then it is a little bit more complex.
Browsers does not allow you to make cross domain AJAX call, which means you can't do it that way.
You need to configure a proxy. It means that you need to create a server which will get the data (it can because your server does not have the browser restriction), and then send it back to you. I can't give you an example because it depend on which programming language you are going to use server side.
If your server and your script are under the same domain, then you are good to go. If you are not using the same domain, you need to add an extra header to the response :
Access-Control-Allow-Origin: *
This is not that simple for a beginner so if you are struggling with anything, don't panic and ask more questions.
You will need to make a "GET" request for the data.
I'd recommend the following steps
http://www.w3schools.com/jquery/jquery_get_started.asp
https://api.jquery.com/jquery.get/
http://www.sitepoint.com/use-jquerys-ajax-function/
Let me know if this is useful!
You can use AJAX to call that url using GET method and get that data into an array. If you are not on the sam domain do include a additional header (Access-Control-Allow-Origin: *) in your server file.