Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, so I am able to get two separate JSON requests and spit out the data separately. What I cannot figure out is how to combine the data from one JSON array to the other. Below is the JS that calls both JSON arrays, the idea is to be able to match the dates from both arrays and spit out the goal data (conversions, completions, value) on each day on the calendar. All of the data should be added to the citationHTML variable.

    var zipcode = '27560';
var appid = '96afa96cadeb7165258ae95b77fdc';
var startdate = '2015-09-01';
var enddate = '2015-09-30';
var timeperiod ='24';

var dataUrl = '//api.worldweatheronline.com/premium/v1/past-weather.ashx?q='+ zipcode +'&format=json&date='+ startdate +'&enddate='+ enddate +'&tp='+ timeperiod +'&key='+ appid

var dataUrl2 = '//westbrookfl.com/wp-content/plugins/CSAnalytics/lib/data/data-GoalValueTotals.php'

//Creates Table for Citation Data
    $.when(
        $.getJSON(dataUrl),
        $.getJSON(dataUrl2)
    ).done (function (data, data2) {
        var data = data[0].data;
        console.log(data, data2);
        var citationHTML = '';
        var channelHTML = '';
        jQuery.each(data, function (i) {
        var weather = data.weather;
            for (var i = 0; i < weather.length; ++i) {
                citationHTML += '<li id="day'+[i]+'" class="day"><div class="date">' + weather[i].date + '</div><div class="svg-icon"><img src="' + weather[i].hourly[0].weatherIconUrl[0].value + '" /></div><div class="data-wrap col2"><p class="data hi-temp"><span>' + weather[i].maxtempF + '</span><sup class="deg ng-scope" data-ng-if="hasValue()">°</sup></p><p class="data lo-temp"><span>' + weather[i].mintempF + '</span><sup class="deg ng-scope" data-ng-if="hasValue()">°</sup></p></div><p class="data desc">' + weather[i].hourly[0].weatherDesc[0].value + '</p></li>';
            }
        })
        jQuery.each(data2[0], function (i, item) {
            channelHTML += '<tr><td class="tg-yw4l">' + item.date + '</td><td class="tg-yw4l">' + (+item.goalConversionRateAll).toFixed(2) + '%</td><td class="tg-yw4l">' + item.goalCompletionsAll + '</td><td class="tg-yw4l">$' + item.goalvalueall + '</td></tr>';
        })
        jQuery('#citation_report').append(citationHTML);
        jQuery('#channeldata_table').append(channelHTML);
    });


Here is fiddle for it as well: https://jsfiddle.net/joseph_a_garcia/s41kr5hj/52/
Posted
Updated 2-Nov-15 6:06am
v3
Comments
Richard Deeming 2-Nov-15 9:52am    
You seem to have forgotten to post the error. Instead, you've posted a line of code.

Use the "Improve question" button to update your question with the error message. Don't forget to indicate which line of your code is throwing the error.
Member 12106757 2-Nov-15 12:07pm    
Thanks, i have updated it with additional information
Richard Deeming 2-Nov-15 12:15pm    
You're missing a couple of semi-colons on the two data URL lines, but I'm not sure if that's the problem.

Your jsfiddle works fine for me in Firefox. What error are you getting?
Member 12106757 2-Nov-15 12:18pm    
It's not an error that I'm getting. I just dont know how to call the data from dataUrl2 on the citationHTML variable (while matching the dates from dataUrl and dataUrl2) to make sure the data is accurate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900