I have the following js file, and I'm trying to create a table with both data from a csv of today and yesterday. I had trouble with race conditions before, so tried using promises now, and ended up at the following code, but it 1) doesn't seem to work 2) disallows all other code to work, for e.g. my 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;
for (var i = 1; i < 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>