html - promises in javascript meddle with the rest of the code -


i have following js file, , i'm trying create table both data csv of today , yesterday. had trouble race conditions before, tried using promises now, , ended @ following code, 1) doesn't seem work 2) disallows other code work, e.g. calendar boot $(document).ready(function() { $('#datetimepicker1').datetimepicker(); });

the .js file:

$(document).ready(function() { $('#datetimepicker1').datetimepicker(); }); var p = function(url){     return new promise(function(resolve, reject){         $.ajax({             url: url,             crossdomain:true,             datatype:"jsonp",             'success': function(response){            $(".domain").append(response.results.collection1[0].date);                 var collection = response.results.collection2;                 (var = 1; < collection.length; i++){                       $(".table-group1").append('<tr> <td>' + collection[i].domain.href + '</td>'+'<td>' + collection[i].dns + '</td>'+'<td> ' + collection[i].mail + '</td>'+'<td> ' + collection[i].web + '</td> </tr>');                 }             resolve(collection);             },             'error': function(e){                 reject(e);             }         })     }) }     p(url_today).     then(function (collection_today) {         return p(url_yesterday).then(function(collection_yesterday){             $(".table-group1").append('<tr><td>' + collection_today.domain.href + '</td>'+'<td>' + collection_today.dns + '</td>'                 +'<td> ' + collection_today.mail + '</td>'+'<td> ' + collection_today.web + '</td> <td>' + collection_yesterday.domain + '</td> <td>'                 + collection_yesterday.dns + '</td><td>'+ collection_yesterday.mail + '</td> <td>'+ collection_yesterday.web + '</td> </tr>');         })     })     .catch(function(e){         console.error(e);     }); 

the html file:

    <!-- calendar -->    <div class="container">     <div class="row">         <div class='col-sm-6'>             <div class="form-group">                 <div class='input-group date' id='datetimepicker1'>                     <input type='text' class="form-control" />                     <span class="input-group-addon">                         <span class="glyphicon glyphicon-calendar"></span>                     </span>                 </div>             </div>         </div>     </div> </div> <!-- table -->  <div class= "container_1"> <div class="panel panel-info">  <table class="table" border="1"> <th class="panel-heading"> </th> <tr class="domain"> </tr> <tr class="table-group1"> </tr>  </table> 

this doesn't address underlying problems logic or best practice use of promises etc. addresses issue of including code stopping other code working

the reason why having issues have syntax errors in code ... e.g. line 15 needs , - last then code isn't liked js lint -

if change following

        $(".table-group1").append('<tr><td>' + collection_today.domain.href + '</td>' + '<td>' + collection_today.dns + '</td>' +             '<td> ' + collection_today.mail + '</td>' + '<td> ' + collection_today.web + '</td> <td>' + collection_yesterday.domain + '</td> <td>' +             collection_yesterday.dns + '</td><td>' + collection_yesterday.mail + '</td> <td>' + collection_yesterday.web + '</td> </tr>'); 

see lines end + , continue on next line, rather lines beginning +

one other issue code run - maybe before dom ready

it looks code should wrapped in $(document).ready not first line


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -