title: JSON.parse: unexpected character at line 1 column 1 of the JSON data (php)
body: <p>I am unable to access json data as it always fails and gives error as 
  SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
  search.php outputs the json data but scripts.js outputs json.parse error
  <strong>script.js</strong></p>
  
  <pre><code>// execute when the DOM is fully loaded
  $(function() {
  
      console.log("1");
  
      $("#q").typeahead({
          autoselect: true,
          highlight: true,
          minLength: 1
      },
      {
          source: search,
          templates: {
              empty: "no places found yet",
              suggestion: _.template("&lt;p&gt;&lt;%- subname %&gt;&lt;/p&gt;")
          }
      });
  
      // re-center map after place is selected from drop-down
      $("#q").on("typeahead:selected", function(eventObject, suggestion, name) {
  
  
     });
  
  
  });
  function search(query, cb)
  {
      // get places matching query (asynchronously)
      var parameters = {
          sub: query
      };
      $.getJSON("search.php", parameters)
      .done(function(data, textStatus, jqXHR) {
          cb(data);
      })
      .fail(function(jqXHR, textStatus, errorThrown) {
          console.log(errorThrown.toString());
      });
  }
  </code></pre>
  
  <p><strong>search.php</strong></p>
  
  <pre><code>&lt;?php
  
      require(__DIR__ . "/../includes/config.php");
      $subjects = [];
      $sub = $_GET["sub"]."%";
      $sql = "SELECT * from subjects where subname LIKE '$sub'";
      echo $sql;
      if($rows = mysqli_query($con,$sql))
      {
          $row = mysqli_fetch_array($rows);
          while($row){
              $subjects[] = [
  
              'subcode' =&gt;$row["subcode"],
              'subname' =&gt; $row["subname"],
              'reg' =&gt; $row["reg"],
              'courseid' =&gt;$row["courseid"],
              'branchid'  =&gt; $row["branchid"],
              'yrsem' =&gt; $row["yrsem"]
              ];
              $row = mysqli_fetch_array($rows);
          }
      }
      // output places as JSON (pretty-printed for debugging convenience)
      header("Content-type: application/json");
      print(json_encode($subjects, JSON_PRETTY_PRINT));
  
  ?&gt;
  </code></pre>