Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON.parse is not working
    primarykey
    data
    text
    <p>I'm having a very strange problem. My JSON.parse does not seem to work. I tried using eval too but that didn't help either. Below is my code:</p> <pre><code>var responseDoc = xmlHttp.responseText; document.getElementById("debug1").innerHTML=responseDoc; var response = JSON.parse(responseDoc); document.getElementById("debug2").innerHTML=response.category; </code></pre> <p>My responseDoc looks like this</p> <pre><code>{"id":null,"category":"dog","price":"4321","name":"new product 123","sku":"1234","success":true} </code></pre> <p>But response.category is <code>"undefined"</code>. Any ideas why this is happening? I've spent hours on it but couldn't figure out. Thanks a lot!</p> <p>*<strong><em>UPDATE</em>*</strong>: </p> <p>Removed stringify as some people suggested -> still not working.</p> <p>If I tried the code below, I get "Uncaught SyntaxError: Unexpected token &lt;" from the console:</p> <pre><code>var response = JSON.parse(xmlHttp.responseText); </code></pre> <p>*<strong><em>UPDATE 2 *</em></strong>: </p> <p>Found the problem. It's because my responseDoc is getting an HTML Doc. Not a JSON Object. Not sure why that happens. This is the code where I process ajax request (I'm using jsp):</p> <pre><code> JSONObject result = new JSONObject(); result.put("success",true); result.put("id",request.getParameter("id")); result.put("name", request.getParameter("name")); result.put("sku",request.getParameter("sku")); result.put("price",request.getParameter("price")); result.put("category",request.getParameter("category")); out.print(result); out.flush(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload