При передаче JSON на сервер получаю ошибку "Unexpected token <", подозреваю что неправильно вставил js код в php, подскажите пожалуйста в чем ошибка.
Серверный код:
<?php
$route = $_POST['route'];
$timeInMinutes = $_POST['timeInMinutes'];
$timeInSeconds = $_POST['timeInSeconds'];
$averageSpeed = $_POST['averageSpeed'];
$distance = $_POST['distance'];
$trackCoords1 = json_decode($route, false);
$final_time_m1 = json_decode($timeInMinutes, false);
$final_time_s_rounded1 = json_decode($timeInSeconds, false);
$aver_speed_km_h_rounded1 = json_decode($averageSpeed, false);
$total_km_rounded1 = json_decode($distance, false);
?>
<script>
var total_km_rounded = '<?php echo $total_km_rounded1; ?>';
document.write('Растояние: </br>' + total_km_rounded);
var final_time_m = '<?php echo $final_time_m1; ?>';
document.write('Время в минутах: </br>' + final_time_m);
var final_time_s_rounded = '<?php echo $final_time_s_rounded1; ?>';
document.write('Время в секундах: </br>' + final_time_s_rounded);
var aver_speed_km_h_rounded = '<?php echo $aver_speed_km_h_rounded1; ?>';
document.write('Средняя скорость: </br>' + aver_speed_km_h_rounded);
</script>
Клиентский код передачи JSON:
$("#sendRoute").live('click', function(){
$.ajax({
url: "http://test.whirlware.biz/server/",
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); }
});
});