I am using express and Node.js. When I run the function below to get the value of an URL,
Json.stringify(url)
gives me the error.
ReferenceError: Json is not defined.
app.get("/id", function (req, res, next) {
var id = req.param("id");
connection.query('SELECT `url` FROM dynamic_url where id =' + req.param("id"), function (error, rows, fields) {
if (err) {
return next(err);
}
var url;
if (rows.length === 0) {
url = 'URL not available in database'
} else {
url = rows[0].url;
}
var i = Json.stringify(url);
res.redirect(i);
});
});
You have capitalization error on your JSON variable name. You need to use -
JSON.stringify(url)
not -
Json.stringify(url)
See the docs.
Its not Json its JSON :
JSON.stringify(url);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With