title: Using json_encode to send html returns “null” string at the end
body: <p>I'm using this to load php functions and send them to javascript in a plugin, like:</p>
  
  <pre><code>function me_nav_query_submit() {
  
      $urlcall = nav_me_paises(); /* fetches a large html string */
      $response = json_encode($urlcall); /* encode to display using jQuery */
  
      //header( "Content-Type: application/json" );
      echo $response;
  
      exit;
  }
  </code></pre>
  
  <p>I insert the html on the page, using</p>
  
  <pre><code>function(response) {
      jQuery('#navcontainer').html(response);
  }
  </code></pre>
  
  <p>and everything works fine, except that i get a "null" string at the very end of the result.</p>
  
  <p><code>json_encode()</code> documentation talks about null strings on non-utf-8 chars, but this doesn't seem to be the case. I've also tried using <code>utf8_encode()</code> with no success. I've read a bunch of other questions here on SO, but most of them either talk about one given value returned as null or bad UTF-8 encoding and in my case everthing just works, and then append "null" to the end. </p>
  
  <p><strong>note:</strong> Defining that header() call is recommended in the WP Codex, but i commented it because it was giving a "headers already sent" error.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT</strong> this is the function called:</p>
  
  <pre><code>function nav_me_paises() {
      ?&gt;
     &lt;ul class="navcategorias"&gt;
          &lt;?php $tquery = $_POST['wasClicked']; ?&gt;
          &lt;?php $navligas = get_terms($tquery,'hide_empty=0') ?&gt;
          &lt;?php foreach ($navligas as $liga) : ?&gt;
              &lt;?php $link = get_term_link($liga); ?&gt;
              &lt;li class="liga"&gt;&lt;a href="&lt;?php echo $link; ?&gt;" &gt;&lt;?php echo $liga-&gt;name; ?&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;?php endforeach; ?&gt;
      &lt;/ul&gt;
      &lt;?php
  }
  </code></pre>