Jump to content

JavaScript get information from server

robeng

Hi! Im wondering if someone knows a site were you can get like temprature, weather etc from colombia and link it into a varible so you can display it on your own website!

Thanks in advance!

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, robeng said:

Hi! Im wondering if someone knows a site were you can get like temprature, weather etc from colombia and link it into a varible so you can display it on your own website!

Thanks in advance!

https://openweathermap.org/api

 

 

That time I saved Linus' WiFi pass from appearing on YouTube: 

A sudden Linus re-appears : http://linustechtips.com/main/topic/390793-important-dailymotion-account-still-active/

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Lacrimas said:

Try this,


var myjson;
$.getJSON("your_api_call_in_here", function(json){
    myjson = json;
});

 

I get an error in the console: XMLHttpRequest cannot load file:///C:/Users/kasta/Desktop/api.openweathermap.org/data/2.5/weather?id=3464008&APPID=SECRET. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Lacrimas said:

So, how do I load it from the server?

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Lacrimas said:

Do you have a local server?

No it is hosted by another company.

If you enter the link in google chrome a page with this will display:

{"coord":{"lon":-44.31,"lat":-19.76},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"base":"stations","main":{"temp":296.103,"pressure":927.64,"humidity":91,"temp_min":296.103,"temp_max":296.103,"sea_level":1023.54,"grnd_level":927.64},"wind":{"speed":3.41,"deg":16.0032},"rain":{"3h":0.185},"clouds":{"all":92},"dt":1484487205,"sys":{"message":0.075,"country":"BR","sunrise":1484469085,"sunset":1484516540},"id":3464008,"name":"Esmeraldas","cod":200}

 

Link to comment
Share on other sites

Link to post
Share on other sites

14 hours ago, robeng said:

I get an error in the console: XMLHttpRequest cannot load file:///C:/Users/kasta/Desktop/api.openweathermap.org/data/2.5/weather?id=3464008&APPID=SECRET. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

You need to use the HTTP prefix in your request URL. For example "http:///api.openweathermap.org/data/2.5/weather?id=3464008&APPID=SECRET".

 

You don't need to set up a local server.

 

Here's my working example:

<html>
<head>
<script>
function myFunction() {
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET", "http://api.openweathermap.org/data/2.5/forecast/city?id=524901&APPID={YOUR_APP_ID_GOES_HERE}", false);
    xmlHttp.send();
    document.getElementById("x").innerHTML = xmlHttp.responseText;
}
</script>
</head>
<body>
    <p id="x"></p>
    <button type="button" onclick="myFunction()">Try it</button>
</body>
</html>

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×