将数据从Javascript传输到php页面

I have a Javascript variable in my file.js that i want to send to map.php then from map.php i want the send it to map2.php:

file.js

//some code
$.post('map.php', { latitude: position.coords.latitude , longitude: position.coords.longitude });
//some code

map.php

<?php 
session_start();
$latitude = $_POST['latitude'];//line 26
$longitude = $_POST['longitude'];////line 27
$_SESSION['latitude'] = $latitude;
$_SESSION['longitude'] = $longitude;?>

map2.php

<?php 
session_start();
$latitude = $_SESSION['latitude'];
$longitude = $_SESSION['longitude'];?>
<script>
var myOrigin= new google.maps.latLng(<?php echo json_encode($latitude); ?>,<?php echo json_encode( $longitude ); ?>);
console.log(myOrigin);
</script>

On map.php i keep getting these errors:

Notice: Undefined index: latitude in C:\wamp\www....  on line 26
Notice: Undefined index: longitude in C:\wamp\www....   on line 27

Any help will be appreciated.

Try:

$.ajax({
  type: "POST",
  url: "map.php",
  data: { latitude: position.coords.latitude , longitude: position.coords.longitude }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

Also, in map.php, personally I like to use $_REQUEST vs $_POST. It picks up both POST and GET variables, rather than having to distinguish between the two.