Note that there are some explanatory texts on larger screens.

plurals
  1. POGet JSON from Javascript to PHP
    primarykey
    data
    text
    <p>I have a javascript function that sends JSON to my server: </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/", 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" }); }); </code></pre> <p>And mix of PHP and JS code that receive and display my JSON data</p> <pre><code>&lt;?php $route = $_POST['route']; $timeInMinutes=$_POST['timeInMinutes']; $timeInSeconds=$_POST['timeInSeconds']; $averageSpeed=$_POST['averageSpeed']; $distance=$_POST['distance']; $trackCoords = json_decode($route, false); $total_km_rounded = json_decode($timeInMinutes, false); $final_time_m = json_decode($timeInSeconds, false); $final_time_s_rounded = json_decode($averageSpeed, false); $aver_speed_km_h_rounded = json_decode($distance, false); echo $trackCoords['coordsarray']; echo $total_km_rounded; echo $final_time_m; echo $final_time_s_rounded; echo $aver_speed_km_h_rounded; ?&gt; &lt;script type="text/javascript"&gt; var total_km_rounded = '&lt;?php echo $total_km_rounded ?&gt;'; document.write('Растояние: ' + total_km_rounded); var final_time_m = '&lt;?php echo $final_time_m ?&gt;'; document.write('Растояние: ' + final_time_m); var final_time_s_rounded = '&lt;?php echo $final_time_s_rounded ?&gt;'; document.write('Растояние: ' + final_time_s_rounded); var aver_speed_km_h_rounded = '&lt;?php echo $aver_speed_km_h_rounded ?&gt;'; document.write('Растояние: ' + aver_speed_km_h_rounded); &lt;/script&gt; </code></pre> <p>But when I send JSON data my server don`t display it. Where did I make a mistake? Maybe I can receive JSON another way?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload