javascript - How to pass client values from browser side to node.js controller -
I am creating a simple node app and using dust on the client side. I am trying to get latitude, LNG from users' location and call the API using the node JS Express framework. So I get latitude, LNG in the customer side from the Geolocation API. I now want to pass the latitude, LNG to the controller so that I can check the API to show user content. Sorry, if it's really original I'm new to both nodes and dust. What have I tried so far? 1. I tried to submit the form using jquery 2. Setting some domain values etc.
$ (document) .ready (function () {var option = {enableHighAccuracy: true, Timeout: 5000, maximum advance: function success (pause) {var crd = pos.coords; document.query selector ("[name = 'latitude']"). Value = crd.latitude; document.query "[Name = 'longitude']"). Value = crd.longitude; console.log ('latitude:' + crd.latitude); console.log ('longitude:' + crd.longitude);}; function error ( Error) {console.warn ('error (' + err.code + '):' + err.message);} navigator.geolocation.getCurrentPosition (success, error, option);});
Controller code:
module.exports = function (router) {router.get ('/', function (rick, race) {// How can I pass the latitude, LAG to the controller from the client?}); }
Call an AJAX call on your root path on the client side and send your router callback Gone Data
Customer
// AJAX Request $ Post ("/ postLatLng", {lat: latVariable, lng: lngVariable});
node
// post late for router post ('/ postLatLng', function (rick, ridge) post request {var lat = Reich Param ("Late"); var lng = req.param ("lng"); // ...});
Comments
Post a Comment