如何将浏览器端的客户端值传递给node.js控制器

我正在构build一个简单的nodejs应用程序,并在客户端使用灰尘。 我正在尝试从用户位置获取lat,lng,并且想要使用节点js express框架进行API调用。 所以我从地理位置api得到客户端的lat,lng。 现在我想将lat,lng传递给控制器​​,这样我就可以查询API来显示用户内容。 对不起,如果这是非常基本的。 我对nodejs和灰尘都很陌生。 我到目前为止尝试了什么? 1.我尝试使用jquery提交表单2.设置一些dom值等

$(document).ready( function() { var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; function success(pos) { var crd = pos.coords; document.querySelector("[name='latitude']").value = crd.latitude; document.querySelector("[name='longitude']").value = crd.longitude; console.log('Latitude : ' + crd.latitude); console.log('Longitude: ' + crd.longitude); }; function error(err) { console.warn('ERROR(' + err.code + '): ' + err.message); }; navigator.geolocation.getCurrentPosition(success, error, options); }); 

控制器代码:

 module.exports = function (router) { router.get('/', function (req, res) { //How do I pass the lat, lng from the client to controller? }); } 

只需在客户端进行ajax调用,然后在路由器callback中获取发送的数据

客户

 //Make the ajax request $.post("/postLatLng",{lat:latVariable,lng:lngVariable}); 

节点

 //hanlde the post request to /postLatLng router.post('/postLatLng', function (req, res) { var lat = req.param("lat"); var lng = req.param("lng"); //... }); 

Express api