json request

Tagged:

Currently contains 2 posts

Avatar

March 18, 2017 23:54

Jolyon Favreau

your service/api looks amazing and i’ve been trying to use it…..but can’t.

while i don’t expect you to create my code for me, there is NO example of a JSON request anywhere on the net and your example is xml only!

i’ve trying to convert something like this (test.js)….


$( document ).ready(function() {
    var ipurl = "https://freegeoip.net/json/";
    $.getJSON( ipurl,function(locate){
      document.getElementById("demo").innerHTML = "<b>" + locate.city + "</b>";

        var url = 'https://api.openweathermap.org/data/2.5/weather?&lat=' + locate.latitude + '&lon=' + locate.longitude + '&units=imperial&APPID=##############';

         $.getJSON( url, function (data){

            var code = data.weather[0].id;
            var hr = (new Date()).getHours();

                  console.log(data);
                  console.log(code);

            var darkOutside = function nightOrDay(condition){
            if (hr > 18){
              return condition + "-n";
            }
            else if (hr < 7) {
              return condition + "-n";
            }
            else{
            return condition + "-d";
            }
          };


           document.getElementById("weathericon").className = "owf owf-" + darkOutside(code);
           document.getElementById("weather").innerHTML = data.weather[0].main;
           document.getElementById("temp").innerHTML = data.main.temp + "&#176;";

         });
     });
   });

…into something i can use through your service.

i’ve looked on github, stackoverflow, google and your own forum….there is no clue how to create a simple json request.

PLEASE ADD ONE!

Avatar

March 20, 2017 13:54

Marco

Hi Jolyon,

In the code sample that you are working on, you should be able to get a response just by replacing the request URL:


$.getJSON( "https://api.weatherunlocked.com/api/current/51.5,-0.12?app_id=APP_ID&app_key=APP_KEY",function(json){
        console.log( "Weather: " + json.wx_desc );
});

more about jquery getJSON:
http://api.jquery.com/jquery.getjson/

code sample javascript:
https://developer.weatherunlocked.com/documentation/localweather/codesamples

Cheers,

Marco

Reply to thread
  1. If you're human, leave this field empty.