I am using servlet to sent data as arraylist to ajax calls.Now on client side i am trying to parse that data into json type but it is giving error as..
SyntaxError: JSON.parse: unexpected character var dbdata=JSON.parse(data);
The values that i am getting ajax success is
[INCOMING, 0, INETCALL, 0, ISD, 31.8, LOCAL, 197.92, STD, 73.2]
Here is my client side ajax code..
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'getdata',
async:false,
dataType: "text",
success: function(data) {
var dbdata=JSON.parse(data);
alert(dbdata);
}
});
});
and here is my servlet code..
ArrayList callcost = new ArrayList();
try {
String strQuery = "";
ResultSet rs = null;
Conexion conexiondb = new Conexion();
conexiondb.Conectar();
strQuery = "SELECT toc,Sum(callcost) as callcost FROM `asteriskcdrdb`.`processeddata_table` group by toc";
rs = conexiondb.Consulta(strQuery);
while (rs.next()) {
String toc = rs.getString("toc").trim();
String cost=rs.getString("callcost").trim();
callcost.add(toc.trim());
callcost.add(cost.trim());
}
out.print(callcost);
System.out.println(callcost);
out.close();
Please guys help me . Thanks in advance..
callcost,calllcoststringify, which takes a JavaScript object or array and returns the JSON string representation of it.