Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery getJSON - ajax parseerror
    text
    copied!<p>I've tried to parse the following json response with both the JQuery getJSON and ajax:</p> <pre><code>[{"iId":"1","heading":"Management Services","body":"&lt;h1&gt;Program Overview&lt;/h1&gt;&lt;h1&gt;January 29, 2009&lt;/h1&gt;"}] </code></pre> <p>I've also tried it escaping the "/" characters like this:</p> <pre><code>[{"iId":"1","heading":"Management Services","body":"&lt;h1&gt;Program Overview &lt;\/h1&gt;&lt;h1&gt;January 29, 2009&lt;\/h1&gt;"}] </code></pre> <p>When I use the getJSON it dose not execute the callback. So, I tried it with JQuery ajax as follows:</p> <pre><code>$.ajax({ url: jURL, contentType: "application/json; charset=utf-8", dataType: "json", beforeSend: function(x) { if(x &amp;&amp; x.overrideMimeType) { x.overrideMimeType("application/j-son;charset=UTF-8"); } }, success: function(data){ wId = data.iId; $("#txtHeading").val(data.heading); $("#txtBody").val(data.body); $("#add").slideUp("slow"); $("#edit").slideDown("slow"); },//success error: function (XMLHttpRequest, textStatus, errorThrown) { alert("XMLHttpRequest="+XMLHttpRequest.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown); } }); </code></pre> <p>The ajax hits the error ans alerts the following:</p> <pre><code>XMLHttpRequest=[{"iId":"1","heading":"Management Services","body":"&lt;h1&gt;Program Overview &lt;/h1&gt;&lt;h1&gt;January 29, 2009&lt;/h1&gt;"}] textStatus=parseerror errorThrown=undefined </code></pre> <p>Then I tried a simple JQuery get call to return the JSON using the following code:</p> <pre><code>$.get(jURL,function(data){ var json = eval("("+data+");"); wId = json.iId; $("#txtHeading").val(json.heading); $("#txtBody").val(json.body); $("#add").slideUp("slow"); $("#edit").slideDown("slow"); }) </code></pre> <p>The .get returns the JSON, but the eval comes up with errors no matter how I've modified the JSON (content-type header, other variations of the format, etc.)</p> <p>What I've come up with is that there seem to be an issue returning the HTML in the JSON and getting it parsed. However, I have hope that I may have missed something that would allow me to get this data via JSON. Does anyone have any ideas?</p>
 

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