When trying to access JSON data in the Controller, it is not being retrieved in the Success function and instead showing an error message "Failed to load resource: the server responded with a status of 406 (Not Acceptable)" or executing the Error function. Can anyone assist me with this issue?
AJAX Call
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
alert("I am okay");
function drawChart () {
$.ajax({
url: "index.html",
type:'get',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
//dataType: "json",
success: function (jsonData) {
alert("Success..............");
alert(jsonData.jData);
var data = new google.visualization.DataTable();
// assumes "word" is a string and "count" is a number
data.addColumn('number', 'Year');
data.addColumn('number', 'Sales');
data.addColumn('number', 'Expenses');
data.addColumn('number', 'Profit');
alert("inside.....");
alert(data);
for (var i = 0; i < jsonData.length; i++)
{
data.addRow([jsonData[i].profit, jsonData[i].sales, jsonData[i].year, jsonData[i].expenses]);
}
alert(data);
var options = {
title: 'Company Details',
};
var chart = new google.visualization.PieChart(document.getElementById('Chart_div'));
chart.draw(data, options);
},
error: function(e)
{
alert('Error: ' + e);
}
});
}
</script>
Controller
@RequestMapping(value = "/index",method = RequestMethod.GET,headers = {"Content-type=application/json"})
@ResponseBody
public JSONArray getshowempPage() throws SQLException, JSONException
{
JSONArray jData=gservice.GraphData();
System.out.println(jData.toString());
//Here i am getting This result
jData = [{"profit":"200","sales":"2000","year":"2014","expenses":"400"},{"profit":"250","sales":"1170","year":"2015","expenses":"460"}]
return jData;
}
Any assistance would be greatly appreciated.