我正在尝试从servlet获取JSON数据到ajax当我在servlet中打印Json数据时它正在打印数据
但是在ajax成功:函数(jsonData)它表示没有定义jsonData变量
的码:
var MostRecent = ListOfObjects.OrderBydescending(x => x.MyDate).First();
Servlet代码是
<script type="text/javascript">
google.charts.load('current', {
callback: function () {
drawChart();
function drawChart() {
$.ajax({
url: 'Get_Sensor',
type: 'get',
dataType:"json",
contentType: "application/json",
success: function (jsonData)
{
var data = new google.visualization.DataTable();
data.addColumn('string', 'word');
data.addColumn('number', 'count');
alert(" ---> "+jsonData.length); **Here i am getting Undefined**
for (var i = 0; i < jsonData.length; i++)
{
data.addRow([jsonData[i].word, jsonData[i].count]);
}
var options = {
title: 'Word Count',
is3D: true
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data,options);
}
});
}
},
packages: ['corechart']
});
</script>
任何建议都会受到赞赏 谢谢。