jquery - Unable get data inside $when $done -


ok, im trying figure out why same 2 pieces not working. 1 works outside of when/done statement 1 need work inside when/done. can take , tell me im doing wrong. im able 2 out of 3 requests working fine.

jquery(function() {       var convextid = 'jdv_electric';     var convapikey = '369281456857b6910b0b8e0b1d7b046c';        var convapisec= '%241%24svutmt1e%24hqqhtuvafoouuz5bfvqle.';      var newconvdata ='https://api.logmycalls.com/services/getcalldetails?criteria[external_ouid]='+convextid+'&criteria[start_calldate]=2015-12-01&criteria[end_calldate]=2015-12-31&api_key='+convapikey+'&api_secret='+convapisec+'&sort_by=id&sort_order=asc';     var goaltotal = 'https://aspentouch.com/wp-content/plugins/csanalytics/lib/data/data-goalvaluetotals.php';     var weatherapi = 'https://api.worldweatheronline.com/premium/v1/past-weather.ashx?q=27560&format=json&date=2015-12-01&enddate=2015-12-31&tp=24&key=5553de26af2e2c672d1042c05800d'      //creates table weather data  var channelhtml = '' var dispositionanswered = ''; var dispositionnoanswer = ''; var totalcallmin = 0; var totalcount = ''; var avgcallduration = ''; var valuecallssingle = ''; var valuecalls = '';     var valuecallminutes = 0;      jquery.when(         jquery.getjson(weatherapi),         jquery.getjson(goaltotal),         jquery.getjson(newconvdata)     ).done (function (data, data2, data3) {         var data = data[0].data;         console.log(data, data2, data3);         var weatherhtml = '';         var lookup = {};         var weather = data.weather;         (var = 0; < weather.length; ++i) {             var key = weather[i].date.replace(/-/g,'');             lookup[key] = i;             weatherhtml += '<li id="day'+[i]+'" class="day day-container"><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('#weather_report').append(weatherhtml);         jquery.each(data2[0], function (i, item) {             var day = jquery("#day" + lookup[item.date]);             day.append('<div class="content"><div class="content-conv-rate"><span class="goal-content">goal conversion rate: </span><span class="goal-value">' + (+item.goalconversionrateall).tofixed(2) + '%</span></div><div class="content-comp"><span class="goal-content">goal completions: </span><span class="goal-value">' + item.goalcompletionsall + '</span></div><div class="content-value"><span class="goal-content">goal value:</span> <span class="goal-value">$' + item.goalvalueall + '</span></div></div>');         })         //i cant 1 work         jquery.each(data3.results, function(i, value) {             channelhtml += '<tr><td class="tg-yw4l">' + data3.results[i].calldate + '</td><td class="tg-yw4l">' + data3.results[i].tracking_number + '</td><td class="tg-yw4l">' + data3.results[i].disposition + '</td><td class="tg-yw4l">' + data3.results[i].duration + '</td><td class="tg-yw4l">' + data3.results[i].id + '</td><td class="tg-yw4l">' + data3.results[i].is_outbound + '</td><td class="tg-yw4l">' + data3.results[i].ouid + '</td><td class="tg-yw4l">' + data3.results[i].repeat_call + '</td><td class="tg-yw4l">' + data3.results[i].caller_id + '</td><td class="tg-yw4l">' + data3.results[i].ringto_number + '</td><td class="tg-yw4l"><audio src="' + data3.results[i].file_url + '" controls></audio></td></tr>';             console.log(channelhtml);         });          //         jquery('.day-container').click(function() {           jquery(this).prev('.highlighter').find('.content').hide();           jquery(this).children('.content').animate({width: 'toggle'});           jquery(this).toggleclass('highlighter');         });         jquery('#conv_table_one').append(channelhtml);     });      jquery('.showsingle').on('click', function () {         jquery(this).addclass('selected').siblings('.anchor').removeclass('selected');         jquery('.goal-metrics').hide();         jquery('.chart-' + jquery(this).data('target') + '-container').show();     });     jquery('.showsingle').first().click();      //this 1 works fine     jquery.getjson(newconvdata, function(data3) {         jquery.each(data3.results, function(i, value) {             totalcount = data3.results.length;              var phonenumbers = data3.results[i].caller_id;              if ( !phonenumbers.match(/^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$/) && data3.results[i].duration > 90 && data3.results[i].disposition === "answered") {                 valuecalls+++1;                 valuecallminutes += parsefloat(data3.results[i].duration) / 60;             }             if (value.disposition === "answered") {dispositionanswered++;}               if (value.disposition === "no answer") {dispositionnoanswer++;}             totalcallmin += parsefloat(data3.results[i].duration) / 60;             avgcallduration = totalcallmin / totalcount;              jquery.each(data3.results, function(i, value) {                 channelhtml += '<tr><td class="tg-yw4l">' + data3.results[i].calldate + '</td><td class="tg-yw4l">' + data3.results[i].tracking_number + '</td><td class="tg-yw4l">' + data3.results[i].disposition + '</td><td class="tg-yw4l">' + data3.results[i].duration + '</td><td class="tg-yw4l">' + data3.results[i].id + '</td><td class="tg-yw4l">' + data3.results[i].is_outbound + '</td><td class="tg-yw4l">' + data3.results[i].ouid + '</td><td class="tg-yw4l">' + data3.results[i].repeat_call + '</td><td class="tg-yw4l">' + data3.results[i].caller_id + '</td><td class="tg-yw4l">' + data3.results[i].ringto_number + '</td><td class="tg-yw4l"><audio src="' + data3.results[i].file_url + '" controls></audio></td></tr>';             });             jquery('#totalcount span').html(totalcount);             jquery('#dispositionanswered span').html(dispositionanswered);             jquery('#dispositionnoanswer span').html(dispositionnoanswer);             jquery('#totalcallmin span').html(totalcallmin.tofixed(2));             jquery('#avgcallduration span').html(avgcallduration.tofixed(2));             jquery('#valuecalls span').append(valuecalls);             jquery('#valuecallminutes span').html(valuecallminutes.tofixed(2));             jquery('#conv_table_two').append(channelhtml);         });          });          //end    }); 

here html:

<div id="monthly-calendar">     <ul id="weather_report" class="week ng-scope first">     </ul> </div> <div>     <table class="tg" id="conv_table_one" border='1'>         <tr>             <th class="tg-yw4l">call date</th>             <th class="tg-yw4l">tracking number</th>             <th class="tg-yw4l">disposition</th>             <th class="tg-yw4l">duration</th>             <th class="tg-yw4l">id</th>             <th class="tg-yw4l">is outbound</th>             <th class="tg-yw4l">ouid</th>             <th class="tg-yw4l">repeat call</th>             <th class="tg-yw4l">caller id</th>             <th class="tg-yw4l">ring number</th>             <th class="tg-yw4l">play audio file</th>         </tr>     </table>     <table class="tg" id="conv_table_two" border='1'>         <tr>             <th class="tg-yw4l">call date</th>             <th class="tg-yw4l">tracking number</th>             <th class="tg-yw4l">disposition</th>             <th class="tg-yw4l">duration</th>             <th class="tg-yw4l">id</th>             <th class="tg-yw4l">is outbound</th>             <th class="tg-yw4l">ouid</th>             <th class="tg-yw4l">repeat call</th>             <th class="tg-yw4l">caller id</th>             <th class="tg-yw4l">ring number</th>             <th class="tg-yw4l">play audio file</th>         </tr>     </table>         </div> 

here fiddle well: https://jsfiddle.net/javapatriot/k3cvb720/

note: browser may hung pulls in data. sorry!

$.when().done() run after code have update elements.

instead of :

jquery.when(     jquery.getjson(newconvdata),     jquery.getjson(goalvaluetotals) ).done (function (data, data2) {    // result processing code  });//end of `done()`  jquery('.totalinv').append(totalcost); jquery('.totalleads').append(totalcompletions); jquery('.perleadvalue').append(perleadvalue); 

move append code inside callback

jquery.when(     jquery.getjson(newconvdata),     jquery.getjson(goalvaluetotals) ).done (function (data, data2) {    // result processing code     jquery('.totalinv').append(totalcost);    jquery('.totalleads').append(totalcompletions);    jquery('.perleadvalue').append(perleadvalue);   });//end of `done()` 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -