Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON messing up when data returned has HTML tags
    primarykey
    data
    text
    <p>I have a PHP page that is returning a JSON object like this:</p> <pre><code> header('Content-Type:application/json'); echo &lt;&lt;&lt;HERE_DOC [ {content: '{row2[contentFull]}', bigimages: '{$row3['catalogFileID']}'}] HERE_DOC; </code></pre> <p>In my main page I have the following jQuery code:</p> <pre><code>jQuery(function() { jQuery("select#rooms").change(function() { var options = ''; jQuery.getJSON("/admin/selection_about.php",{id:jQuery(this).val(), ajax:isAjax}, function(j) { for (var i = 0; i &lt; j.length; i++) { options = j[i].topImage; document.getElementById('content1').value = j[i].bigimages; } }) }) }) </code></pre> <p>So basically in my main page, I have a drop down. When an option is selected, it fires off an Ajax request back to the server. I get the data in JSON format and then a textarea, with ID 'content1', is updated based on that JSON object.</p> <p>The JSON object looks like this:</p> <pre><code>[ { content: '&lt;SPAN STYLE= "" &gt;&amp;quot; this is some text&amp;quot; blah blah, &amp;quot; some more `text&amp;quot; now some linebreaks; &lt;BR&gt;&lt;BR&gt;some more text and then another` linebreak.`&lt;BR&gt;`&lt;/SPAN&gt;', bigimages: 'cfil1069' } ]` </code></pre> <p>But there are errors that occur here and my textarea does not get updated. However, if I hardcode plain simple text to be returned in the JSON object, then my textarea is updated.</p> <p>Is there a condition for which data in the JSON object should not have HTML tags?</p> <p>Edit:</p> <p>As suggested, I changed my code to following in PHP code: </p> <pre><code>$arr = array ('content'=&gt;$rest1,'bigimages'=&gt;$row3['catalogFileID']); echo json_encode($arr); </code></pre> <p>However now in my jQuery code:</p> <p>length of j is 'undefined' ...</p> <pre><code> jQuery.getJSON("/admin/selection_about.php",{id: jQuery(this).val(), ajax: isAjax}, function(j) { alert('here3: ' + j.length); // this shows undefined for (var i = 0; i &lt; j.length; i++) { document.getElementById('content1').value = j[i].content; } }) </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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