I am trying to send an json object array from a servlet to javascript .where I all get the array and parse . my ajax call the servlet appropriately but unable to recieve the json array at the javascript end please help
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException {
System.out.println("Post!!");
response.setContentType("application/json");//since sendign jsonArray toString
PrintWriter out = response.getWriter();
try {
Marker marker=new Marker( 40.72318,-74.03605);//
JSONArray arrayObj=new JSONArray();
arrayObj.add(marker);
System.out.println(marker.toString());
out.print(arrayObj);
} finally {
out.flush();
out.close();
}
}
This is my ajax call in javascript where I am trying to get the json object array form the servlet.
$.ajax({
url:'test',
dataType:'json',
type:'POST',
success:function(data){
<%System.out.println(" success");%>
console.log(data);
alert('got json hopefully');
alert(data);
//
},
error:function(jxhr){
<%System.out.println(" faliure");%>
console.log(jxhr.responseText);
}
});