-1

I have succeeded in parsing a response from the Wunderground API and displaying a response for the "current" weather conditions of a state and certain city. This tells me the exact temp and current conditions outside at the time of the call.

I now need the ability and I am having trouble getting a 3 day forecasted response to work along with the current weather condition response I have.

My end result I want a 3 day forecasted result and all of those days to contain High and Low Temps for those days only.

Example:

  • Day 01 - Monday High / Low
  • Day 02 - Tuesday High / Low
  • Day 03 - Wednesday High / Low

Day 01 would technically be the current day it is.

Please if anyone can take a look at my script as of now and help add what is missing I would appreciate it.

Here is my JS

    jQuery(document).ready(function($) {

      /* Edit these variables */
      var api = "2ea138a9dd52eabe";
      var state = "TX";
      var city = "Dallas";

      $.ajax({
      url: "http://api.wunderground.com/api/" + api + "/forecast/conditions/q/" + state + "/" + city + ".json",
      dataType : "jsonp",
      success : function(parsed_json) {
          var icon_url_json = "http://icons.wxug.com/i/c/f/" + parsed_json['current_observation']['icon'] + ".gif";
          var icon_json = '<img src ="' + icon_url_json + '" />';
          var temp_json = parsed_json['current_observation']['temp_f'];
            temp_json += "<span>°F</span>";
          var condition_json = parsed_json['current_observation']['weather'];
          var real_feel_json = "Feels Like " + parsed_json['current_observation']['feelslike_f'] + "°F";
          var wind_json = 'Winds are ' + parsed_json['current_observation']['wind_string'];
          var location_json = city + ', ' + state;


          var forecastArray = parsed_json['forecast']['txt_forecast']['forecastday'];
                if (forecastArray !== null) {

                    for (var i = 0; i < forecastArray.length; i++) {

                        if (forecastArray[i] !== null) {
                            //use can use this to assing directly to HTML element    
                            console.log(forecastArray[i]['period']);
                            console.log(forecastArray[i]['title']);
                            console.log(forecastArray[i]['fcttext']);

                        }

                    }}

      document.getElementById("weather-icon").innerHTML = icon_json;
      document.getElementById("temp").innerHTML = temp_json;
      document.getElementById("condition").innerHTML = condition_json;  
      document.getElementById("real-feel").innerHTML = real_feel_json;
      document.getElementById("wind").innerHTML = wind_json;
      document.getElementById("location").innerHTML = location_json;

      }
      });
    });

I have also put this up here for people to look at it working as of now. http://jsfiddle.net/supasmo/9d5bh/2/

Seth
  • 23
  • 7

1 Answers1

-1

You can actually fetch for next 10 days http://jsfiddle.net/xxk7S/ Updated. Here is the Updated Code

 for(var some in parsed_json.forecast.txt_forecast.forecastday){
             console.log("*************");
          $("#nxtDays").append("<b>"+parsed_json.forecast.txt_forecast.forecastday[some].title+" </b> <br />"+
 parsed_json.forecast.txt_forecast.forecastday[some].fcttext+"<br />");                              console.log(parsed_json.forecast.txt_forecast.forecastday[some].title);
      }
Santhosh Kumar
  • 190
  • 3
  • 10
  • This is very close to what I am needing. Inside the parse I need to pull the **simpleforecast** information. An EXAMPLE: _"simpleforecast": { "forecastday": [ "period":1, "high": { "fahrenheit":"43", "celsius":"6" }, "low": { "fahrenheit":"30", "celsius":"-1" }_ – Seth Feb 26 '14 at 15:14
  • You need to knw how to fetch value from JSON? – Santhosh Kumar Feb 26 '14 at 18:10
  • Yeah, I am needing a little help fetching those specific values. – Seth Feb 28 '14 at 15:57