How can I pass the variable skip value from front end JS to the Node Serve.JS file? Currently these are the codes that I have. Any idea where I have written wrongly?
Server.js (NodeJs)
app.get("/api/routes", function(req , res){
// Configure the request
const skip = req.query.skip;
var options = {
url: 'http://dataservice/trainroutes?$skip='+skip,
method: 'GET',
encoding: null,
headers: {
AccountKey: 'XXX',
accept: 'application/json'
}
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.writeHead(200, response.headers);
res.write(body);
res.end();
}
else {
res.send("Error");
}
})
});
Front end JS:
function busseries(){
var skip = 14000;
$.ajax({
url: "/api/routes?skip="+skip,
success: function(results5) {
//Set result to a variable for writing
var objs5 = JSON.stringify(results5);
var routetimeobjs5 = JSON.parse(objs5);
console.log(routetimeobjs5)
}
});
}
Pass it with template literals like so.
url: `/api/routes?skip=${skip}`