title: PHP + Javascript error: Unexpected token D
body: <p>I have an error:</p>
  
  <blockquote>
    <p>Unexpected token D</p>
  </blockquote>
  
  <p>When I try to send JSON from JavaScript to PHP. I know that error is caused on server side and I tried to fix it, but then I get another errors like <code>Unexpected input</code>, <code>Unexpected end</code> and similar.</p>
  
  <p>I am trying to fix it during 1 week and have no result. My goal is to send data to server and make server show it without errors, how can I do it?</p>
  
  <p>My client code:</p>
  
  <pre><code>$("#sendRoute").live('click', function () {
      trackCoords_str = JSON.stringify(trackCoords);
      final_time_m_str = JSON.stringify(final_time_m);
      final_time_s_rounded_str = JSON.stringify(final_time_s_rounded);
      aver_speed_km_h_rounded_str = JSON.stringify(aver_speed_km_h_rounded);
      total_km_rounded_str = JSON.stringify(total_km_rounded);
      $.ajax({
          url: "http://test.whirlware.biz/server/index.php",
          type: "POST",
          data: {
              route: trackCoords_str,
              timeInMinutes: final_time_m_str,
              timeInSeconds: final_time_s_rounded_str,
              averageSpeed: aver_speed_km_h_rounded_str,
              distance: total_km_rounded_str,
          },
          dataType: "json",
          success: function (){alert("success!");},
          error: function (xhr, ajaxOptions, thrownError) {
              alert(xhr.responseText);
              alert(thrownError);
          }
      });
  });
  </code></pre>
  
  <p>My server code:</p>
  
  <pre><code> $route = $_POST['route'];
   $timeInMinutes = $_POST['timeInMinutes'];
   $timeInSeconds = $_POST['timeInSeconds'];
   $averageSpeed = $_POST['averageSpeed'];
   $distance = $_POST['distance'];
  
   $trackCoords1 = json_encode($route);
   $final_time_m1 = json_encode($timeInMinutes);
   $final_time_s_rounded1 = json_encode($timeInSeconds);
   $aver_speed_km_h_rounded1 = json_encode($averageSpeed);
   $total_km_rounded1 = json_encode($distance);
  
   echo "Distance: &lt;/br&gt;"; echo $distance;
   echo "Time in minutes: &lt;/br&gt;"; echo $timeInMinutes;
   echo "Time in seconds: &lt;/br&gt;"; echo $timeInSeconds;
   echo "Average speed: &lt;/br&gt;"; echo $averageSpeed;
  </code></pre>