I want to put var inside var in javascript but don't know how.
this is my code
var success;
var fail;
$.ajax({
type:"POST",
url:base_url+"/api/getDataCount",
data: {error: true},
async:true,
dataType : 'JSON',
success: function(data, status, xhr){
success = data.count;
},
error: function(request, textStatus, errorThrown){
console.log('Error retio bot');
}
});
$.ajax({
type:"POST",
url:base_url+"/api/getDataCount",
data: {error: false},
async:true,
dataType : 'JSON',
success: function(data, status, xhr){
fail = data.count;
},
error: function(request, textStatus, errorThrown){
console.log('Error retio bot');
}
});
// Donut Chart
var donutChartEl = document.querySelector('#donut-chart'),
donutChartConfig = {
chart: {
height: 350,
type: 'donut'
},
legend: {
show: true,
position: 'bottom'
},
labels: ['Success', 'Fail'],
series: [success, fail],
.......
I want to put success var inside donutChartEl var in the series. but I can't do that. is there anyone who know a better way for this. please help.