I want to use ajax response as a global variable. It couldn't be used outside 0f success statement. So,
here's my code:
<script>
var id = $('#@Model.Id').val();
var connectionData;
$.ajax({
type: "POST",
url: '@CustomUrl.SendConnectionTime(@Model.Id)',
data: id,
success: function(response2) {
connectionData = response2;
},
error: function () {
alertify.set('notifier', 'position', 'bottom-right');
alertify.error("Veri göndermede hata oluştu.");
}
});
</script>
and I want to use connectionData in another component like:
var myChart = new Chart(canvas,
{
type: 'line',
data: {
labels: times,
datasets: [
{
label: dataConnectionTitle,
data: connectionData,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderWidth: 1
}
]
},
options: {
scales: {
yAxes: [
{
ticks: {
beginAtZero: true
}
}
]
}
}
}
);
},
error: function() {
alertify.set('notifier', 'position', 'bottom-right');
alertify.error("Veri göndermede hata oluştu.");
}
});
but when I'm debugging connectionData seems undefined.