I have encountered various similar issues, but none of them have provided a solution for my specific question. On my server, I generate a JSON string and place it in the response:
List<String> list = getSomeList();
JSONArray jsArray = new JSONArray(list);
System.out.println(jsArray);
response.setContentType("application/json");
response.getWriter().write(jsArray.toString());
However, in my javascript handling function, when I attempt to alert the response, it alerts the entire page!
function handleResponse(){
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response){
alert(response); //alert all page!
var list = JSON.parse(response.toJSON()); //does not work!
}
}
Question: How can I isolate just the jsArray in JavaScript?
P.S. My understanding is that my JSON.parse(response.toJSON()) fails because the response contains the entire page?