Подскажите где я совершил ошибку, что у меня выходит ошибка: "Now the error is: Uncaught SyntaxError: Unexpected token o in JSON at position 1"
Вот кусок кода в котором проблема:
$(function () {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: 'json',
url: '/Chart/GetVotings',
}).data (function (votings) {
votings = $.parseJSON(votings);
$: each(votings, function (index, data) {
chartData.labels.push(data.name);
chartData.datasets[0].data.push(data.voice);
});
});
});
Вот весь код:
<canvas id="ChartVote" width="300" height="200"></canvas>
<script type="text/javascript" charset="utf-8">
$(function () {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: 'json',
url: '/Chart/GetVotings',
}).done(function (votings) {
console.log(votings);
votings = $.parseJSON(votings);
$: each(votings, function (index, data) {
chartData.labels.push(data.name);
chartData.datasets[0].data.push(data.voice);
});
});
});
var ctx = document.getElementById("ChartVote");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [],
datasets: [{
label: '# of Votes',
data: [],
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)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
votings = $.parseJSON(votings);
? Добавьтеconsole.log(votings);
перед этой строкой и вставьте то, что выведено в консоль, в Ваш вопрос.ChartController.GetVotings
.