Q:

Sending HTML5 geolocation results back to Node/Express Server

I am using HTML5 geolocation to retrieve a users lat/lng, and would like to pass it back to the server to compare it against a list of shop lat/lngs coords and return the nearest five . 
The geolocation API is returning the lat/lng cooridinates client side with no issue at all, I just cannot find a way to return the information back to the server and render a new page at the same time. 
I have tried using $.post method, attaching the coords to data: object. 
Client side Javascript 
function sendToServer(lat,lng){
     $.ajax({
          type: "POST",
          url: "/search",
          data: {lat: lat, lng: lng},
          success: function(data){
               alert('Successful');
          },
     });
}

I can see from a console.log call server side that the coords are being passed successfully . server.js
app.post('/search', function(req,res){
     console.log(req.body);                           <-- does show lat/lng coords
     res.render('./pages/search' , {
          shops: coords.getNearestFive(req.body)      <-- just to give idea 
     });
});

I have only passed the shops object with the render to give you an idea of what I intend to to with data, I have not tried this yet.
'./pages/search' will not render to the client, I have read other posts suggesting using the $.ajax is not a good way to try and carry this out, however I cannot find a solution. I have tried using the 'GET' method but I cannot retrieve the lat/lng coords from server-side even though the page does load correctly. 
What is strange is I have checked the request/response using google network tools and the repsonse does show the rendered './pages/search', this is not being reflected in the browser though. 
This is my anchor that acts as a button to get the coords
<a href="/search" class="geoSearch"> Find My Location! </a>

Does anyone know , how I could pass and get the coordinates as well as being able to load the selected page? Thanks
**** Update **** 
I have managed to get the lat/lng details out from the serverside by using req.query and wrapping the res.render() call in a setTimeout function which really does feel pretty hacky.  
app.get('/search', function(req,res){
     console.log(req.query);             <-- logs passed lat/lng
     res.render('./pages/search');
});

Clientside click handler 
$('.geoSearch').on('click', function(){
     getCoords();
});

Clientside ajax request 
function sendToServer(lat,lng){
     $.ajax({
          type: "GET",
          url: "/search",
          contentType: "application/json",
          data: JSON.stringify({lat: lat, lng: lng}),
          success: function(data){
               alert('Successful');
          },
     });
}

Serverside 
app.get('/search', function(req,res){
     var beQuick = req.query;
     console.log(beQuick);
     setTimeout(function(){              
          res.render('./pages/search');
     },1000);
});

Is there a better way of allowing req.query to fill the variable serverside without having to add a delay via setTimeout on rendering the new page? Thanks

A:

If anybody else is having this type of issue , I have found a relatively easy way to pass data back and forth using websockets. 
To do this you require socket.io as a dependency in your project and some extra code. 
Serverside JS 
//allow socket IO to latch onto HTTP server
var server = http.createServer(NYise);
var io = require('socket.io').listen(server);

//reacts to an event emitted on the client side 
io.on('connection', function(socket){
     socket.on('coords', function(yourDataPassed){
          //whatever you intened to do with your data
     });
});

Clientside JS 
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>

     //emit back to server  <-- my code is held in another function. 
     var socket = io();
     socket.emit('coords', {lat: lat, lng: lng});

My code is held in a different function so may look confusing. Links to SocketIO documentation for further info - http://socket.io/docs/. 

