title: AJAX request via jQuery from PHP responses null
body: <p>I want to receive data using AJAX from PHP which asks a database for some data. All i get from AJAX is <code>NULL</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/txpmS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/txpmS.png" alt="received from Firefox Debugger"></a></p>
  
  <p>When i alert the result (e.g. data.name) it says <code>undefined</code>.</p>
  
  <p>HTML, AJAX and jQuery are in the <code>index.php</code> while PHP in <code>edit.php</code> is.</p>
  
  <p>The AJAX request I use ...</p>
  
  <pre><code>$('div[data-toggle="edit"]').click(function() {
      var editid = $(this).attr('id').replace('edit','');
      $.ajax({
          cache: false,
          type: 'GET',
          url: 'edit.php',
          data: editid,
          dataType: 'JSON',
      }).done(function(data) {
          $('#mainlabel').modal('show');
          $('input[name=add_name]').val(data.name);
          $('input[name=add_date]').val(data.date);
          $('input[name=add_image]').val(data.image);
          $('input[name=add_info]').val(data.info);
      }).fail(function(jqXHR, message) {
          alert(message);
      });
  });
  </code></pre>
  
  <p>... to receive data from this PHP code.</p>
  
  <pre><code>&lt;?php
      require_once('main.conf');
      require_once('db.php');
  
      $stmt = $con-&gt;prepare("SELECT * FROM datas d WHERE d.dataid = ?");
      $stmt-&gt;bind_param("i", $_GET["editid"]);
      $stmt-&gt;execute();
      $result = $stmt-&gt;get_result();
      $stmt-&gt;close();
  
      while ($row = $result-&gt;fetch_assoc()) {
          $editname  = $row["name"];
          $editdate  = date("Y-m-d", strtotime($row["date"]));
          $editimage  = $row["image"];
          $editinfo  = $row["additionalinfo"];
      }
  
      $return[] = array("name" =&gt; $editname,
                        "date" =&gt; $editdate,
                        "image" =&gt; $editimage,
                        "info" =&gt; $editinfo,
                        "getid" =&gt; $_GET["editid"]); //only for debugging
  
      header('Content-Type: application/json; charset=UTF-8');
      echo json_encode($return);
  ?&gt;
  </code></pre>
  
  <p>When i invoke the this code manually via <code>edit.php?editid=547</code> the JSON-result looks like it should.</p>
  
  <pre><code>0   
      name    "Mike Minus"
      date    "2015-05-12"
      image   "employee.jpg"
      info    "some additional info"
      getid   "547"
  </code></pre>
  
  <p>With the expected informations i want to fill some input-boxes.</p>
  
  <pre><code>&lt;div class="modal-body mx-3"&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="add_name" class="col-form-label"&gt;Name:&lt;/label&gt;
          &lt;input class="form-control validate" type="text" name="add_name" value=""&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="add_name" class="col-form-label"&gt;Datum:&lt;/label&gt;
          &lt;input class="form-control" type="date" name="add_date" size="8" value=""&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="add_image" class="col-form-label"&gt;Bild:&lt;/label&gt;
          &lt;input class="form-control" type="text" name="add_image" value=""&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label for="add_info" class="col-form-label"&gt;Zusatzinfos:&lt;/label&gt;
          &lt;input class="form-control" type="text" name="add_info" value=""&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="btn btn-info btn-sm" data-toggle="edit" id="edit547"&gt;
      &lt;i class="fa fa-pencil-square-o"&gt;&lt;/i&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I know there are quite a lot of possible solutions in SO. Using <code>echo</code> instead of <code>return</code> in the PHP code, the appropriate <code>application/json</code> header or other techniques. Nothing could help till yet.</p>